How to send a mail by ckicking the button using java

hi,
how to send a mail by clicking the button (like payroll silp in that contain one button if we click that it autometically go through the mail as a attachment) pls frd to me my gmail is [email protected]

Hi,
It seems we are doing the homework for you; to make you start with something; look at the sample code below and try to understand it first then put the right values
to send an email with an attachement.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Main {
      * @param args
     public static void main(String[] args) {
          // Create the frame
          String title = "Frame Title";
          JFrame frame = new JFrame(title);
          // Create a component to add to the frame
          JComponent comp = new JTextField();
          Action action = new AbstractAction("Button Label") {
               // This method is called when the button is pressed
               public void actionPerformed(ActionEvent evt) {
                    System.out.println("sending email with attachment");
                    sendEmail();
          // Create the button
          JButton button = new JButton(action);
          // Add the component to the frame's content pane;
          // by default, the content pane has a border layout
          frame.getContentPane().add(comp, BorderLayout.SOUTH);
          frame.getContentPane().add(button, BorderLayout.NORTH);
          // Show the frame
          int width = 300;
          int height = 300;
          frame.setSize(width, height);
          frame.setVisible(true);
     protected static void sendEmail() {
          String from = "me@localhost";
          String to = "me@localhost";
          String subject = "Important Message";
          String bodyText = "This is a important message with attachment";
          String filename = "c:\\tmp\\message.pdf";
          Properties properties = new Properties();
          properties.put("mail.stmp.host", "localhost");
          properties.put("mail.smtp.port", "25");
          Session session = Session.getDefaultInstance(properties, null);
          try {
               MimeMessage message = new MimeMessage(session);
               message.setFrom(new InternetAddress(from));
               message.setRecipient(Message.RecipientType.TO, new InternetAddress(
                         to));
               message.setSubject(subject);
               message.setSentDate(new Date());
               // Set the email message text.
               MimeBodyPart messagePart = new MimeBodyPart();
               messagePart.setText(bodyText);
               // Set the email attachment file
               MimeBodyPart attachmentPart = new MimeBodyPart();
               FileDataSource fileDataSource = new FileDataSource(filename) {
                    @Override
                    public String getContentType() {
                         return "application/octet-stream";
               attachmentPart.setDataHandler(new DataHandler(fileDataSource));
               attachmentPart.setFileName(filename);
               Multipart multipart = new MimeMultipart();
               multipart.addBodyPart(messagePart);
               multipart.addBodyPart(attachmentPart);
               message.setContent(multipart);
               Transport.send(message);
          } catch (MessagingException e) {
               e.printStackTrace();
}The sample above is not ideal so you need to go through it and start to ask me some questions if you have
Let me know if you miss something
Regards,
Alan Mehio
London,UK

Similar Messages

  • How to send a mail prior to the due date

    Hi all,
                 I would like to send a mail prior to the due date. Please let me know how to go to the previous step after the loop is executed once in workflows.
    Thanks,
    Sirisha N.

    Hi all,
                 I would like to send a mail prior to the due date. Please let me know how to go to the previous step after the loop is executed once in workflows.
    Thanks,
    Sirisha N.

  • How to send e-mail alert to the user job is successful or failed.

    Hi Experts,
    I have scheduled a job using DBMS_JOB Package; in this job I am calling a procedure.
    How can we send an e-mail(alert) to the user if the job is successful (or) job fails.
    If the job is successfully completed, then we have to send mail as “Job is completed successfully along with job name”.
    If the job fails we have to send email as “error message of the job along with job name”(why the job is failed).
    This alert should be sending automatically no manual intervention.
    Please help me.
         CREATE OR REPLACE PROCEDURE APPS_GLOBAL.arc_procedure (P_ID IN NUMBER)
         IS
         CURSOR C IS SELECT id,table_name,archive_table_name,where_condition
         FROM apps_global.control_ram
         WHERE id = p_id
         ORDER BY id, table_name;
         BEGIN
            FOR I IN C
            LOOP
               EXECUTE IMMEDIATE
                  'INSERT INTO '
               || I.ARCHIVE_TABLE_NAME
               || '
         (SELECT * FROM '
               || I.TABLE_NAME
               || ' WHERE '
               || I.WHERE_CONDITION
               || ')';
               EXECUTE IMMEDIATE
                  'DELETE FROM '
               || I.TABLE_NAME
               || ' WHERE '
               || I.WHERE_CONDITION
               || '';
               COMMIT;
            END LOOP;
         EXCEPTION
            WHEN OTHERS
            THEN
               ROLLBACK;
               DBMS_OUTPUT.PUT_LINE (
               'An error was encountered - ' || SQLCODE || ' -ERROR- ' || SQLERRM);
         END arc_procedure;
         /This is my job.
    DECLARE
      X NUMBER;
    BEGIN
      SYS.DBMS_JOB.SUBMIT
      ( job       => X
       ,what      => 'APPS.arc_procedure(1);'
       ,next_date => to_date('05/01/2013 00:00:00','dd/mm/yyyy hh24:mi:ss')
       ,interval  => 'TRUNC(SYSDATE+1)'
       ,no_parse  => FALSE
      SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
    COMMIT;
    END;
    /Thanks in advance.

    Hi,
    I think you can do by creating mailing procedures and call it in the loop and outside the loop.
    There would be two procedure one in inside loop which will execute after successfull completion of the loop.
    Other would be in the exception block like i shown in the below code you have written;
    V_variable_1 you can use as a parameter for what is the error occured.
    like suppose your mailing procedure name is Status_email and Status_email_1.
    CREATE OR REPLACE PROCEDURE APPS_GLOBAL.arc_procedure (P_ID IN NUMBER)
         IS
         CURSOR C IS SELECT id,table_name,archive_table_name,where_condition
         FROM apps_global.control_ram
         WHERE id = p_id
         ORDER BY id, table_name;
    V_VARIABLE_1 NUMBER;
    V_VARIABLE_2 VARCHAR2(400);
         BEGIN
            FOR I IN C
            LOOP
               EXECUTE IMMEDIATE
                  'INSERT INTO '
               || I.ARCHIVE_TABLE_NAME
               || '
         (SELECT * FROM '
               || I.TABLE_NAME
               || ' WHERE '
               || I.WHERE_CONDITION
               || ')';
               EXECUTE IMMEDIATE
                  'DELETE FROM '
               || I.TABLE_NAME
               || ' WHERE '
               || I.WHERE_CONDITION
               || '';
               COMMIT;
                     STATUS_EMAIL;
            END LOOP;
         EXCEPTION OTHERS THEN
    V_VARIABLE_1 :=SQLCODE;
    V_VARIABLE_2 :=SQLERRM;
               ROLLBACK;
    STATUS_EMAIL_1(V_VARIABLE_1,V_VARIABLE_2);
         END arc_procedure;
         / You can refer to sample email procedure i have created for you.
    CREATE OR REPLACE PROCEDURE STATUS_EMAIL
    AS
       v_From       VARCHAR2(80) := 'EMAIL_ID';
       v_Recipient  VARCHAR2(80) := 'EMAIL_ID';
    --YOU CAN SEND EMAIL TO MORE THAT ONE USER SO YOU CAN USE LIKE BELOW VARIABLE....
       v_Recipienttt  VARCHAR2(80) := 'EMAIL_ID';
       v_Subject    VARCHAR2(80) := 'SUBJECT_FOR_THE_MAIL';
       v_Mail_Host  VARCHAR2(30) := 'MAIL_SERVERS_HOST_IP(SMTP_SERVER)';
       v_Mail_Conn  utl_smtp.Connection;
       crlf         VARCHAR2(2)  := chr(13)||chr(10);
    BEGIN
      v_Mail_Conn := utl_smtp.Open_Connection(v_Mail_Host);
      utl_smtp.Helo(v_Mail_Conn, v_Mail_Host);
      utl_smtp.Mail(v_Mail_Conn, v_From);
      utl_smtp.Rcpt(v_Mail_Conn, v_Recipient);
      utl_smtp.Rcpt(v_Mail_Conn, v_Recipienttt);
    --OPEN DATA CONNNECTION
      UTL_SMTP.OPEN_DATA(v_mail_conn);
    --MAIL HEADER
      utl_smtp.write_DATA(v_Mail_Conn,'Date: '   || to_char(sysdate, 'DD-MON-YYYY hh:mi:ss AM') || crlf);
      utl_smtp.write_DATA(v_Mail_Conn,'From: '   || v_From || crlf );
      utl_smtp.write_DATA(v_Mail_Conn,'Subject: '|| v_Subject || ||crlf);
      utl_smtp.write_DATA(v_Mail_Conn,'To: '     || v_Recipient || crlf);
      utl_smtp.write_DATA(v_Mail_Conn,'Cc: '       || v_Recipienttt ||','|| crlf);
    --MAIL BODY
      utl_smtp.write_DATA(v_Mail_Conn,'MIME-Version: 1.0'|| crlf );
      utl_smtp.write_DATA(v_Mail_Conn,'Content-Type: multipart/mixed;'|| crlf );
      utl_smtp.write_DATA(v_Mail_Conn,' boundary="-----SECBOUND"'|| crlf ||crlf );
      utl_smtp.write_DATA(v_Mail_Conn,'-------SECBOUND'|| crlf );
      utl_smtp.write_DATA(v_Mail_Conn,'Content-Type: text/plain;'|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,'Content-Transfer_Encoding: 7bit'|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,'Procedure is successfully complited without error'|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,null|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,null|| crlf);
    utl_smtp.write_DATA(v_Mail_Conn,null|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,'Dear All, '|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,'Procedure is successfully complited without error'||'.' ||crlf);
      utl_smtp.write_DATA(v_Mail_Conn,null|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,null|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,null|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,null|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,'Regards, '|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,null|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,'any_name '|| crlf);
      utl_smtp.write_DATA(v_Mail_Conn,null|| crlf);
      utl_smtp.write_data(v_Mail_Conn, utl_tcp.CRLF ||'This mail is auto generated.');
      --CLOSE CONNECTION
      UTL_SMTP.CLOSE_DATA(v_mail_conn);
      utl_smtp.Quit(v_mail_conn);
    EXCEPTION
      WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
        raise_application_error(-20000, 'Unable to send mail: '||sqlerrm);
    END;
    /cheers..

  • How to Send Notification to Manager of the Employee using Dynamic Action..

    Hi All,
    I am sending a notification using the Dynamic Action for an Infotype.. I am able to send mail using distribution list but I have a requirement to send the notification to employee manager. I am able to determine the Line Manager ID calling the subroutine in the dynamic action. But I am not sure how to send the notification to the manager.
    If the email's are maintained in distribution list if I specify the text id in the feature M0001 and distribution list the notifications are sent. I am not sure how to pass the line manager id to get the same notification..
    I have seen the option REC1 but infotype 0001 in not having the line manager id..

    Used the Function Module RH_GET_LEADING_POSITION.
    Thanks..

  • How to send an mail to my email by using shell scripting

    Hi,
    I have shell script which generates some text file with text information. Now i want to send over the information available in the text file to my mail id.
    Can anyone give me over the syntax or the script.?
    Thanks a lot
    With Regards
    Vedavathi E

    same typo
    should read
    mailx -s 'subject for mail message ' your_email_address < text_file_to_be_sent
    Guido

  • How to send one mail if multiple updates happend using alert

    Hi all,
    I have one requirement.i had created one alert on a table.
    It will fire only for update of the table.but i am getting mails on each update.
    If 10 records updated then i am getting 10 mails.Is there any way to get one mail to show all the updated records in one mail.
    reply me if anybody known.It would be helpfull to me.
    Thanks,
    Kumar.

    Hi Kumar,
    936453 wrote:
    Hi all,
    I have one requirement.i had created one alert on a table.
    It will fire only for update of the table.but i am getting mails on each update.
    If 10 records updated then i am getting 10 mails.Is there any way to get one mail to show all the updated records in one mail.Please see old threads which can help you on this
    https://forums.oracle.com/forums/search.jspa?threadID=&q=Periodic+AND+Alert+AND+Multiple&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    https://forums.oracle.com/forums/search.jspa?threadID=&q=Duplicate+AND+Alert&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    ;) AppsMasti ;)
    Sharing is Caring

  • IIneed code  to send  & receive mails  to MS OutLook Express using java

    Hi Friends,
    Please help me in the following area..
    I need code to send and receive mails and attachments to MicoSoft OutLookExpress in java,
    please give me the steps and entire code. Thanks In advance
    Thanks & Regards
    Kiran
    [email protected]

    Hi Masijade,
    Thanks for your replay,
    i found 1 solution at http://www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274
    but where he asked us to include class files from the follwing 2 links :
    1. Javasoft's JavaMail class files which can be downloaded from
    http://www.javasoft.com/products/javamail/index.html
    2. JavaBeansTM Activation Framework extension or JAF (javax.activation). It is available at http://java.sun.com/beans/glasgow/jaf.html..
    the problem is i am unable to download class files from 1st link. where i down loaded JAF1.1.1. jar file from 2nd link,
    can you assist on this toppic please and where can we finf java mail class files.
    Thanks & Regards
    Kiran
    [email protected]

  • How to activate a specific profile of the Firefox using java coding?

    Hi Folks,
    I have some query regarding activating the Profiles of the Firefox. Whenever i open the Firefox, the profile manager will be prompting for the profile to be activated. I want to perform such similar operation through java coding. Let us assume, I have three profiles named default, office and personal. I need to invoke the Firefox with a specific profile, office. How to proceed further? Your suggestion will be highly appreciated...
    Thanks in Advance,
    RealStuff, Mike

    String s = "Less than 20";
    while(s.length() < 20) {
         s += " ";
    System.out.println(s + " " + s.length());Mark

  • How need to take screen shot of the screen using java.awt.Robot from javafx

    1) I am displaying a Stage which is having an image and shapes in it and wanted to take the screen shot as and when i move the shape( which moves the stage ).
    I am trying to java.awt.Robot, but i am getting headless exception. I used
    @Override
    public void start(final Stage primaryStage) {
    // creating some images and shapes
    Platform.runLater(new Runnable() {
    @Override
    public void run() {
    // update();
    public void update() {
    if (stg.isShowing()) {
    ScreenCapture.capture(stg.getX() + 2, stg.getY() + 2, (int) boundsOfCircle.getBoundsInParent().getWidth(), (int) boundsOfCircle.getBoundsInParent().getHeight());
    magnifierImageView.setImage(new Image(SCREEN_SHOT_FILE));
    public static void capture(final double x, final double y, final int width, final int height) {
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    try {
    System.out.println("x ="+x +" y = "+y +" width "+width +" height ="+height);
    Robot robot = new Robot();
    } catch (Exception e) {
    System.out.println("exception arised while taking the screen shot ");
    e.printStackTrace();
    The above code throws headless exception.
    2) The second issues is have a image & i am dividing the image into different rows and cols( images of same size ). This is i am doing using awt. and i wanted to load those different images into
    javafx images . I am facing the issues when i try to load the images into javafx.

    hi,
    click on print screen button in your keyboard.
    open a word document and do Ctrl V .
    *Reward points if it helped

  • How to send E-mails using JSP

    I developed a system where users can login and check for updated information and documents. But the changes are made once or twice in a year. I want to send email after changing the documents. I stored email addresses in the DB. Now the question is how to send e-mails to concerned users without using external software (Outlook, etc.). [Considering same subject and message for all e-mails.]

    Go to Java Mail forum:
    http://forum.java.sun.com/forum.jsp?forum=43

  • Code for reading the and placing the file using java webservice

    Hi All,
    Can anybody can guide me on how to read a file and place the file using java.
    Let  me know if any code is available which has been completed using java.
    Regards,
    Rahul

    Hi,
    The "square" symbol that you are referring to is probably a CRLF (Carriage Return - Life Feed) Control Character.
    This is more commonly known as a "Enter" at the end of a line / sentence.
    To clean this character from strings in Java, please use:
    String patternStr = "(?m)$^|[\\r\\n]+\\z";
    String replaceStr = " ";
    Pattern pattern = Pattern.compile(patternStr);
    Matcher matcher = pattern.matcher(inputStr);
    return matcher.replaceAll(replaceStr);
    Hope that helps.
    Thanks.
    p256960.

  • How to send a mail in workflow keeping 1 receiver in CC and the other in TO

    Hi,
    Can anybody tell me how to send a mail in workflow keeping 1 receiver in CC and the other in TO.
    I need to send a mail to an employee keeping his/her manager in CC through workflow.
    Regards,
    Lavanya

    Hi Lavanya,
    I dont think its possible using Send mail step type.
    But it can be done by using the FM SO_NEW_DOCUMENT_SEND_API1. Just create a method and Call this FM accordingly.
    Thanks,
    Viji.

  • How to send external mails to the user

    Dears,
    How to send external mails to the user who creates the sales document (Quotation)
    Can you please suggest what modification required in the FM
    Thanks,
    pinky

    You can have a partner function like 'Created by' and use an exit to populate the User ID to this partner function(dont have the system right now but i think this can be done with standard partner detr. procedure also)
    Then, create an Output type for that Partner function with transmission medium as 'External Send'. You can use the standard SAP program to trigger the email. To send the actual email after the output is trigerred, the link connection has to be set up be BASIS but if you want to check, then goto SOST and see if the email got trigerred or not.

  • Need to send a mail back to the user in Sender Mail adapter Scenario

    Hi all,
    I have a scenario where the user fills the Price form  or the Article form (which is a Adobe Form).When the user clicks on the "submit" button,the form is converted into xml , gets attached to the mail and sent to PI.
    Now the user sometimes attaches the pdf directly instead of submitting the form. This results in the mail being sent
    with pdf  as attachment.
    Now my requirement  is to send a mail back to the user asking them to send an xml  instead of a pdf.
    How can this be done ?
    Kindly let me know friends.
    Quick Response is appreciated.

    hi Sanjay,
    Have a look on Michal's blog, it's for JMS, but it works for others: [PI/XI: Quick tip: Preserving attributes of XI messages via MultipartHeaderBean|PI/XI: Quick tip: Preserving attributes of XI messages via MultipartHeaderBean]
    Mickael

  • How to send a mail in pdf format file in sbwp??

    how to send a mail in pdf format file in sbwp?? and how to read the content of the mail?

    Refer the following link for Sample Program:
    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

Maybe you are looking for

  • Automatic Clearing for Partial Payments

    Hi All, I have posted a partial payment with all the permutations and combinations and trying it to clear with F.13 but clearing is not happening. Can anyone advise how to go about it.

  • I subscribe to Acrobat Pro XI online and my computer is not recognizing it

    I've subscribed to Acrobat Pro XI and pay $21 and change monthly.  Currently Acrobat does not recognize my subscription and keeps asking me to purchase Acrobat Pro to export PDF to Word, Excel to PDF, etc.   In other words, I'm not able to use any of

  • Header Detail relation with Character Mode problem

    I am having a weird problem with a report on a Epson LX-300 printer. If the report style is tabular the spacing between lines is the same as that shown in the preview. But once I use the report style Group above, the verticle spacing turns doubled be

  • No thumbnails in Photos :-(

    Thumbnails of my photos in Photos on my iPad 2 are blank. Via iTunes, I synced the last 12 months photos (all 900 taken with my iPhone) from my Mac to my iPad 2, and although I can access the pictures full-screen by tapping the blanks and also run sl

  • OS 1.3.1 released

    See here for update notes: http://forums.palm.com/palm/board/message?board.id=webossoftware&thread.id=2813 Post relates to: Pre p100eww (Sprint)