Methods to send a mail

Hi,
please bear with me, and any mistakes i make, as i'm not that much of an expert in the whole area of mail sending and servers. At the minute our software is using javamail to send mails through a SMTP host. fairly simple, nothing too complicated about it.
the problem is that the company that uses out software is changing all their mail servers to Microsoft Exchange servers. At the minute it seems like they will not be opening the ports for SMTP (or IMAP, LDAP, POP3 etc.), so that we can continue to use the mail function in our software.
So is there any other way that we can send e-mails using our software. We were told we could use an interface called MAPI, but having done a little search i haven't been able to find too much info (apart from what it means ;-) about how i can use it with java. Can anyone possibly point me in the right direction.
Thanks for your time
Sok

Hey,
With MIDP it's little bit hard to make application which connects to POP3 or IMAP server because there is no support for socket connections. But if your phone support sockets, it's not hard to
make a simple e-mail client for j2me.
But i've heard that it's possible to make somekind hacked socket connection for MIDP but i'm not sure will that work on actually phones.
- fuse

Similar Messages

  • Auto-reaction method not sending e-mail

    Hi everyone,
    We are trying to set-up email notificacions for cancelled jobs. So far I've configured SCOT and RZ20 succesfully. The alerts are triggered and the auto-reaction method is active and ready but it's not sending automatics e-mails. If I click on the auto-reaction method status and manually start auto-reaction method it sends the e-mails, but I haven't been able to make it work automatically.
    So far I've read every possible thread in SAP forums about the issue and I also have checked the following notes:
    Note 671780 - Only trigger auto-reaction method with certain alerts
    Note 502959 - RZ20: External e-mail as auto-reaction
    Note 939616 - CCMS auto-reactions: Help with troubleshooting
    Note 760821 - Auto-reactions no longer work with email
    Note 939616 - CCMS auto-reactions: Help with troubleshooting
    Note 176492 - Automatic email when an alert occurs (RZ20)
    I have tried all the possible control options for method CCMS_OnAlert_Email (currently is executed as a periodically job). I have checked all the jobs generated in RZ21 and still can't get it to work.
    This e-mails alerts are to be triggered locally by each SAP productive system. I've already tried to configure this monitoring alert in two of our developing system with similar behaviour: no automatic e-mail is getting send.
    Please, advice me on what I should do. I know I'm missing some
    configuration but I can't figure out which one.
    Best regards

    Is the job SAP_CCMS_MONI_BATCH_DP running?
    Please note the run time status: "Run required" means,
    the alert was triggered, but the auto-reaction method does not start until the next time the CCMS method dispatcher (SAPMSSY8) runs. This can last up to 5 minutes if alerts are generated asynchronously (for example, by an active data collector).
    However, the next time the CCMS method dispatcher runs, the auto-reaction method should be executed and the status of the node should be READY.
    If the RUN_REQUIRED status does not disappear, it could be for a number of reasons:
    - If MTE is present on the local system:
    The auto-reaction method must not be defined as the central auto-reaction method.
    - If MTE is present on another monitored system and a central auto-reaction method was defined:
    Is one of the above true in your case?
    An agent from the monitored system must be logged on to the central system, and this agent must be active. Please check whether these agents are active or not in Rz21 and try Re-Registering it.
    You can also refer to SNOTE: 939616, 1265906
    In the below link search for "RUN required"
    http://help.sap.com/saphelp_nwpi71/helpdata/en/49/945f2b9ee72222e10000000a42189d/content.htm
    Regards,
    Arjun

  • Exchange 2010 - Method to send e-mail when the WAN IP is dynamic

    Hello,
    I am writing due to the fact that I cannot send e-mail from my Exchange 2010 Server to my Yahoo! address for testing. When trying to do so, I get the following error message:
    mta1106.mail.gq1.yahoo.com gave this error:
    Mail from xxx.xxx.xxx.xxx not allowed - 5.7.1 [BL21] Connections not accepted from IP addresses on Spamhaus PBL; see
    http://postmaster.yahoo.com/errors/550-bl21.html [550]
    As one can see, because my IP address is residential, I cannot send e-mail to all addresses on the web. I really would like to use this as my primary contact, and thought of using a proxy. Can someone recommend a good proxy, or workaround for this? I am
    sorry for posting in Exchange 2013, but I couldn't find the 2010 forum. Thank you to all who reply.
    Mike

    Thank you for your reply,
    I have set up DynDNS, and I am currently using my own domain name. The problem was I needed to configure a smart SMTP host, or relay server on my send connector. I decided to go with SMTP2GO, as they are cheap, and allow you to send 20 e-mails a day for
    free. When the money is right, I plan to upgrade.
    Thank you for your help.
    Mike

  • Method to send e-mail

    Hi Guys,
    Can anyone of you guys help me with an alternative standard method I can use to send the email. It has to be coded in Java.
    Thanx

    One can send mail using Java mail API's. You just need to include activation.jar, mail.jar, mailapi.jar to your classpath.
    public static void postMail(String recipients[], String subject,
                String message, String from) throws MessagingException {
            boolean debug = false;
            //Set the host smtp address
            Properties props = new Properties();
            props.put("mail.smtp.host", "hostName");
            // create some properties and get the default Session
            Session session = Session.getDefaultInstance(props, null);
            session.setDebug(debug);
            // create a message
            Message msg = new MimeMessage(session);
            // set the from and to address
            InternetAddress addressFrom = new InternetAddress(from);
            msg.setFrom(addressFrom);
            InternetAddress[] addressTo = new InternetAddress[recipients.length];
            for (int i = 0; i < recipients.length; i++) {
                addressTo[i] = new InternetAddress(recipients);
    msg.setRecipients(Message.RecipientType.TO, addressTo);
    // Optional : You can also set your custom headers in the Email if you Want
    // msg.addHeader("MyHeaderName", "myHeaderValue");
    // Setting the Subject and Content Type
    msg.setSubject(subject);
    msg.setContent(message, "text/plain");
    Transport.send(msg);

  • Send different mails on different days automatically-Auto Responder

    I need to develop an Auto Responder application where my application has to send different mails to different types of Auto Responder customers.These mails should be sent to these customers every x days after their subscription i.e., once a customer has subscribed for this Auto Responder he will be recieving a mail 3rd day after subscription,then 7 days after subscription and then 10 days after subscription.This will vary on the particular auto responder to which the client has subscribed.
    I got the suggestion that using timer and timer task classes in the java mail will be helpful.But can anyone tell me how to use these methods to send different mails to different customers on different days. I need it urgent.

    I need to develop an Auto Responder application where my application has to send different mails to different types of Auto Responder customers.These mails should be sent to these customers every x days after their subscription i.e., once a customer has subscribed for this Auto Responder he will be recieving a mail 3rd day after subscription,then 7 days after subscription and then 10 days after subscription.This will vary on the particular auto responder to which the client has subscribed.
    I got the suggestion that using timer and timer task classes in the java mail will be helpful.But can anyone tell me how to use these methods to send different mails to different customers on different days. I need it urgent.

  • Sending a mail from a handheld device.

    Hi!
    What are the standard methods to send a mail from a hand held device using J2ME? I managed to do it by setting up a Java Web Server running a servlet which sends out a mail, if you provide it with the mail body and the e-mail address. I called this servlet from the MIDlet, and it works fine from the J2MEWTK.
    Also, i want to know whether this would work when we port this onto an actual device? And where would the servlet run then?
    Thanks & Regards!
    Akhil

    Hey,
    With MIDP it's little bit hard to make application which connects to POP3 or IMAP server because there is no support for socket connections. But if your phone support sockets, it's not hard to
    make a simple e-mail client for j2me.
    But i've heard that it's possible to make somekind hacked socket connection for MIDP but i'm not sure will that work on actually phones.
    - fuse

  • Send different mails automatically on different days-Auto Responder

    I need to develop an Auto Responder application where my application has to send different mails to different types of Auto Responder customers.These mails should be sent to these customers every x days after their subscription i.e., once a customer has subscribed for this Auto Responder he will be recieving a mail 3rd day after subscription,then 7 days after subscription and then 10 days after subscription.This will vary on the particular auto responder to which the client has subscribed.
    I got the suggestion that using timer and timer task classes in the java mail will be helpful.But can anyone tell me how to use these methods to send different mails to different customers on different days. I need it urgent.

    Hi
    in the last reply, i mentioned using of timer and timertask classes to send mails.
    I got ur problem. I believe the Days X is fixed for each auto responder. I mean for auto responder1 days are 3,7,10 , for autoresponder2 days are 5,8,10 ... etc
    R u using any database, if yes follow Soultion 1 otherwise follow Solution2
    1)
    Create two tables in database
    table a is autoresponders table
    schema
    Autoresponderid
    AutoResponderDescription
    AutoResponderMailFormat
    AutoResponderDays(comma deliminated numbers ex: 1,3,5,10.. ) ( i belive Days x is fixed and with varying difference, if it is fixed difference ie 1, 5, 9 with a diff of 4 then we need autoresponderinterval instead of autoresponderDays )
    Table b is CustomerTable
    CustomerID
    Customer Name
    AutoResponderID(Foreign key to autorespondertable)
    Fill out appropriate responders data and customer data
    Now almost the problem is solved.
    I am focusing on main task sending mail
    I have explained already how to send mail in JSP forum for your question. Please refer that.
    Suppose we assume autorespondertable contains 5 rows.
    and customertable contains 10 rows(10 customers)
    Now the logic is
    Create a common TimerTask which has attributes same as autoresponder row.
    Create a Thread(TimerTask in this case), for each row in autoresponder table(in our case 5 TimerTask 's are created)
    Follow these steps(Implement the logic in run method of TimerTask).
    1) Read rows of all customers whose autoresponder is this id
    2) Notice there subscription date, do some work on that date and compare with autoresponderdays data. (suppose if customer subscribtion date is 20/07/2005, todays date is 23/07/2005, if autoresponder day is 3 , take the diff between two dates and compare with autoresponder date) if yes
    Read MailFormat for that autoresponder and add customer name, blah blah, use JavaMail Mail api and send it . and
    3) Important this TimerTask must be scheduled for every day
    i,e. Please have a look to my reply in JSP forum. It should be
    INTERVAL=1000*60*60*24 (1 day)
    4) it checks every day all the autoresponders
    If u want me to write the code, i can provide that
    cheers
    Rajendra Bandi

  • How to send a mail as .txt attachment ,As data is seperated by pipeline

    Hi ,
    I got a requirement to send a mail in .txt format (Using OOPS) and the data inside the mail is seperated by '|'  Pls help me in this regard.
    i have written a mail to send the mail in .xls it is working fine for me in .xls but i dont know how to write the same for txt where data should be seperated by '|'.
    Regards
    sas
    Ps:  i am attaching my code. and please specify where i need to modify to achieve the same. and any perfromance enhacements are also welcome.
    *& Report  ZGBTEST02
    REPORT  YSAS_MAIL2.
    *Changes done by sas
    *PARAMETERS: P_MAIL TYPE AD_SMTPADR OBLIGATORY, " G C by sas
    *P_MAIL1 TYPE AD_SMTPADR OBLIGATORY." G by sas
    tables: adr6.
    SELECT-OPTIONS:p_eaddr FOR adr6-SMTP_ADDR NO INTERVALS .
    *end of changes by sas
    DATA: I_GLT0 TYPE STANDARD TABLE OF GLT0.
    DATA: I_MARA  TYPE STANDARD TABLE OF MARA.  " MARA Entries
    *      I_MARC  TYPE STANDARD TABLE OF MARC.  " MARC Entries
    DATA: L_TEXT  TYPE CHAR255.  " Text
    DATA: L_LINES TYPE I,
          L_SIZE  TYPE SOOD-OBJLEN.
    " Size of Attachment
    * Mail related
    DATA: I_CONTENT         TYPE   SOLI_TAB, " Mail content
          I_ATTACH          TYPE   SOLI_TAB, " Attachment
          I_ATTACH1         TYPE   SOLIX_TAB. " Attachment
    DATA: L_SEND_REQUEST    TYPE REF TO    CL_BCS,
                                                " E-Mail Send Request
          L_DOCUMENT        TYPE REF TO    CL_DOCUMENT_BCS,
                                                " E-Mail Attachment
          L_RECIPIENT       TYPE REF TO    IF_RECIPIENT_BCS,
                                                " Distribution List
          L_SENDER          TYPE REF TO    IF_SENDER_BCS,
                                                " Address of Sender
          L_UNAME           TYPE           SALRTDRCPT,
                                                " Sender Name(SY-UNAME)
          L_BCS_EXCEPTION   TYPE REF TO    CX_DOCUMENT_BCS,
                                                " BCS Exception
          L_ADDR_EXCEPTION  TYPE REF TO    CX_ADDRESS_BCS,
                                                " Address Exception
          L_SEND_EXCEPTION  TYPE REF TO    CX_SEND_REQ_BCS.
    " E-Mail sending Exception
    *Constants------------------------------------------------------------*
    CONSTANTS: C_TAB(1) TYPE C VALUE
               CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
                                         " Tab Character
               C_CR(1)  TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF,
                                         " Line Feed for End-Of_line
               C_EXT    TYPE SOODK-OBJTP VALUE 'XLS'. " XLS Extension
    START-OF-SELECTION.
      SELECT * FROM MARA INTO TABLE I_MARA UP TO 20 ROWS.
      IF SYST-SUBRC EQ 0.
    *    SELECT * FROM MARC INTO TABLE I_MARC FOR ALL ENTRIES IN I_MARA WHERE MATNR = I_MARA-MATNR.
      ENDIF.
    *select * from glt0 into table i_glt0.
    * Preparing body of the Mail
      MOVE 'SAP Material Master Records' TO L_TEXT.
      APPEND L_TEXT TO I_CONTENT.
      CLEAR L_TEXT.
      APPEND L_TEXT TO I_CONTENT.
      MOVE 'Thanks,' TO L_TEXT.
      APPEND L_TEXT TO I_CONTENT.
      MOVE 'SAP MM' TO L_TEXT.
      APPEND L_TEXT TO I_CONTENT.
    * Creates persistent send request
      TRY.
          L_SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
    * Creating Document
          L_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
                                        I_TYPE  = 'RAW'
                                        I_TEXT  = I_CONTENT[]
                                        I_SUBJECT = 'SAS MASTER Records' ).
    * Preparing contents of attachment with Change Log
          PERFORM PREPARE_ATTACHMENT.
          DESCRIBE TABLE I_MARA LINES L_LINES.
    * Size to multiplied by 2 for UNICODE enabled systems
          L_SIZE = L_LINES * 2 * 255.
    * Adding Attachment
          CALL METHOD L_DOCUMENT->ADD_ATTACHMENT
            EXPORTING
              I_ATTACHMENT_TYPE    = C_EXT
              I_ATTACHMENT_SIZE    = L_SIZE
              I_ATTACHMENT_SUBJECT = 'MARA Details'
    *          i_att_content_hex    = i_attach[].
              I_ATT_CONTENT_TEXT   = I_ATTACH[].
    *      DESCRIBE TABLE I_MARC LINES L_LINES.
    * Size to multiplied by 2 for UNICODE enabled systems
    *      L_SIZE = L_LINES * 2 * 255.
    ** Adding Attachment
    *      CALL METHOD L_DOCUMENT->ADD_ATTACHMENT
    *        EXPORTING
    *          I_ATTACHMENT_TYPE    = C_EXT
    *          I_ATTACHMENT_SIZE    = L_SIZE
    *          I_ATTACHMENT_SUBJECT = 'MARC Details'
    *          I_ATT_CONTENT_HEX    = I_ATTACH1[].
    **          i_att_content_text   = i_attach1[].
    * Add document to send request
          CALL METHOD L_SEND_REQUEST->SET_DOCUMENT( L_DOCUMENT ).
          DATA:LR_SENDER TYPE REF TO IF_SENDER_BCS,
               LR_SEND TYPE REF TO CL_BCS.
    * Preparing the sender object
    *      LR_SENDER = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( sy-uname ).
           DATA: L1_UNAME TYPE SY-UNAME.
           L1_UNAME = SY-UNAME.
           LR_SENDER = CL_SAPUSER_BCS=>CREATE( L1_UNAME ).
    * Setting the sender
          CALL METHOD L_SEND_REQUEST->SET_SENDER
            EXPORTING
              I_SENDER = LR_SENDER.
    * E-Mail
       LOOP AT P_EADDR.
          TRANSLATE P_EADDR-LOW TO LOWER CASE.
          L_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( P_EADDR-LOW ).
          CALL METHOD L_SEND_REQUEST->ADD_RECIPIENT
            EXPORTING
              I_RECIPIENT  = L_RECIPIENT
              I_EXPRESS    = 'U'
              I_COPY       = ' '
              I_BLIND_COPY = ' '
              I_NO_FORWARD = ' '.
           IF SY-subrc EQ 0.
              WRITE:/'** SUCCESS:  Email Sent to', p_eaddr-LOW COLOR COL_NORMAL.
            ELSE.
              WRITE:/'** ERROR: Failed to send Email to',p_eaddr-LOW COLOR COL_NEGATIVE .
            ENDIF.
          ENDLOOP.
    *Trigger E-Mail immediately
          L_SEND_REQUEST->SET_SEND_IMMEDIATELY( ' ' ).
          CALL METHOD L_SEND_REQUEST->SEND( ).
          COMMIT WORK.
        CATCH CX_DOCUMENT_BCS INTO L_BCS_EXCEPTION.
        CATCH CX_SEND_REQ_BCS INTO L_SEND_EXCEPTION.
        CATCH CX_ADDRESS_BCS  INTO L_ADDR_EXCEPTION.
      ENDTRY.
    *&      Form  PREPARE_ATTACHMENT
    FORM PREPARE_ATTACHMENT .
      FIELD-SYMBOLS: <LFS_TABLE>,    " Internal table structure
                     <LFS_CON>.      " Field Content
      DATA: L_TEXT TYPE CHAR1024.     " Text content for mail attachment
      DATA: L_CON TYPE STRING. "(50) TYPE c.        " Field Content in character format
      DATA: L_STR TYPE STRING,
            L_STR1 TYPE STRING.
      DATA: LS_SOLIX TYPE SOLIX.
    * Columns to be tab delimeted
      LOOP AT I_MARA ASSIGNING <LFS_TABLE>.
        DO.
          ASSIGN COMPONENT SY-INDEX OF STRUCTURE <LFS_TABLE>
                 TO <LFS_CON>.
          IF SY-SUBRC NE 0.
            CONCATENATE C_CR L_TEXT INTO L_TEXT.
    *        CONCATENATE l_str c_cr l_text INTO l_str.
    *        ls_solix-line = l_text.
    *        APPEND ls_solix TO i_attach.
            APPEND L_TEXT TO I_ATTACH.
            EXIT.
          ELSE.
            CLEAR: L_CON.
            MOVE <LFS_CON> TO L_CON.
            CONDENSE L_CON.
            IF SY-INDEX = 1.
              CLEAR: L_TEXT.
              MOVE L_CON TO L_TEXT.
            ELSE.
              CONCATENATE L_TEXT L_CON INTO L_TEXT
                 SEPARATED BY C_TAB.
            ENDIF.
          ENDIF.
        ENDDO.
      ENDLOOP.
    ** Columns to be tab delimeted
    *  LOOP AT I_MARC ASSIGNING <LFS_TABLE>.
    *    DO.
    *      ASSIGN COMPONENT SY-INDEX OF STRUCTURE <LFS_TABLE>
    *             TO <LFS_CON>.
    *      IF SY-SUBRC NE 0.
    *        CONCATENATE C_CR L_TEXT INTO L_TEXT.
    **        CONCATENATE l_str c_cr l_text INTO l_str1.
    *        LS_SOLIX-LINE = L_TEXT.
    *        APPEND LS_SOLIX TO I_ATTACH1.
    *        EXIT.
    *      ELSE.
    *        CLEAR: L_CON.
    *        MOVE <LFS_CON> TO L_CON.
    *        CONDENSE L_CON.
    *        IF SY-INDEX = 1.
    *          CLEAR: L_TEXT.
    *          MOVE L_CON TO L_TEXT.
    *        ELSE.
    *          CONCATENATE L_TEXT L_CON INTO L_TEXT
    *             SEPARATED BY C_TAB.
    *        ENDIF.
    *      ENDIF.
    *    ENDDO.
    *  ENDLOOP.
    *  i_attach1[] = i_attach[].
    ENDFORM.                    " PREPARE_ATTACHMENT

    Hi Sas,
    I have copied the code and executed and it is working fine. I'm getting the text attachement in the email.
    * Adding Attachment
          CALL METHOD L_DOCUMENT->ADD_ATTACHMENT
            EXPORTING
              I_ATTACHMENT_TYPE    = 'TXT'          "  C_EXT   My change
              I_ATTACHMENT_SIZE    = L_SIZE
              I_ATTACHMENT_SUBJECT = 'MARA Details'
    *          i_att_content_hex    = i_attach[].
              I_ATT_CONTENT_TEXT   = I_ATTACH[].
    CONCATENATE i_mara-MATNR
                             i_mara-ERSDA
                             i_mara-ERNAM
                             i_mara-LAEDA
                   INTO   L_TEXT
                 SEPARATED BY '|'.

  • How to send a mail as .txt attachment ?

    Hi all,
    I got a requirement to write code for sending mail in oops.
    i have written code for .xls which is working fine. But requirement is to send the mail in the format of txt.
    i just only chnge the .xls to .txt where i can see the output properly in sap but problem is that i am unable to get the proper alignment. when i execute the report and see the output in sost i can see the attachment.i am downloading the attachment there only(Our server is not configured to get the mails directly) .So when i open the saved text file on my pc the output is appearing as follows...
    pernr nachn vorna
            0001 L0001 F0001
                0002 L0002 F0002
                   0003 L0003 F0003
                         0004 L0004 F0004...
    Where it should come in straight line as follows in my o/p code..
    pernr nachn vorna
    0001 L0001 F0001
    0002 L0002 F0002
    0003 L0003 F0003
    0004 L0004 F0004...
    i am puttin g my code ..please correct me where i am wrong .....waiting for your valuabel inputs..
    *& Report  ZGBTEST02
    REPORT  YSAS_MAIL2.
    *Changes done by sas
    *PARAMETERS: P_MAIL TYPE AD_SMTPADR OBLIGATORY, " G C by sas
    *P_MAIL1 TYPE AD_SMTPADR OBLIGATORY." G by sas
    TABLES: ADR6.
    SELECT-OPTIONS:P_EADDR FOR ADR6-SMTP_ADDR NO INTERVALS .
    *end of changes by sas
    DATA: I_GLT0 TYPE STANDARD TABLE OF GLT0.
    *DATA: I_pernr  TYPE STANDARD TABLE OF pa0002.  " MARA Entries
    DATA: BEGIN OF I_PERNR OCCURS 1 ,
    PERNR TYPE PA0002-PERNR,
    NACHN TYPE PA0002-NACHN,
    VORNA TYPE PA0002-VORNA,
    END OF I_PERNR..
    *      I_MARC  TYPE STANDARD TABLE OF MARC.  " MARC Entries
    DATA: L_TEXT  TYPE CHAR255.  " Text
    DATA: L_LINES TYPE I,
          L_SIZE  TYPE SOOD-OBJLEN.
    " Size of Attachment
    * Mail related
    DATA: I_CONTENT         TYPE   SOLI_TAB, " Mail content
          I_ATTACH          TYPE   SOLI_TAB, " Attachment
          I_ATTACH1         TYPE   SOLIX_TAB. " Attachment
    DATA: L_SEND_REQUEST    TYPE REF TO    CL_BCS,
                                                " E-Mail Send Request
          L_DOCUMENT        TYPE REF TO    CL_DOCUMENT_BCS,
                                                " E-Mail Attachment
          L_RECIPIENT       TYPE REF TO    IF_RECIPIENT_BCS,
                                                " Distribution List
          L_SENDER          TYPE REF TO    IF_SENDER_BCS,
                                                " Address of Sender
          L_UNAME           TYPE           SALRTDRCPT,
                                                " Sender Name(SY-UNAME)
          L_BCS_EXCEPTION   TYPE REF TO    CX_DOCUMENT_BCS,
                                                " BCS Exception
          L_ADDR_EXCEPTION  TYPE REF TO    CX_ADDRESS_BCS,
                                                " Address Exception
          L_SEND_EXCEPTION  TYPE REF TO    CX_SEND_REQ_BCS.
    " E-Mail sending Exception
    *Constants------------------------------------------------------------*
    CONSTANTS: C_TAB(1) TYPE C VALUE
               CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
                                         " Tab Character
               C_CR(1)  TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF,
                                         " Line Feed for End-Of_line
               C_EXT    TYPE SOODK-OBJTP VALUE 'TXT'. " XLS Extension
    START-OF-SELECTION.
      SELECT PERNR NACHN VORNA  FROM PA0002 INTO CORRESPONDING FIELDS OF TABLE I_PERNR UP TO 20 ROWS.
    *select * from glt0 into table i_glt0.
    * Preparing body of the Mail
    *  MOVE 'SAP Material Master Records' TO L_TEXT.
    *  APPEND L_TEXT TO I_CONTENT.
    *  CLEAR L_TEXT.
    *  APPEND L_TEXT TO I_CONTENT.
    *  MOVE 'Thanks,' TO L_TEXT.
    *  APPEND L_TEXT TO I_CONTENT.
    *  MOVE 'SAP MM' TO L_TEXT.
    *  APPEND L_TEXT TO I_CONTENT.
      MOVE '<BR>Attached is your HRIS report(s) generated from the Firm''s' TO L_TEXT.
      APPEND L_TEXT TO I_CONTENT.
      MOVE ' Human Resources  Information System (SAP).' TO L_TEXT.
      APPEND L_TEXT TO I_CONTENT.
      MOVE '<BR>  ' TO L_TEXT.
      APPEND L_TEXT TO I_CONTENT.
      MOVE '<BR>This is an automated report.' TO L_TEXT.
      APPEND L_TEXT TO I_CONTENT.
    *        MOVE '<BR>  ' TO l_text.
    *        APPEND l_text TO i_content.
      MOVE '<BR>  ' TO L_TEXT.
      APPEND L_TEXT TO I_CONTENT.
    *        MOVE '<BR>Please do not reply to this email' TO l_text.
    *        APPEND l_text TO i_content.
    *        MOVE '<BR>  ' TO l_text.
    *        APPEND l_text TO i_content.
      MOVE '<BR>Thank you.' TO L_TEXT.
      APPEND L_TEXT TO I_CONTENT.
    * Creates persistent send request
      TRY.
          L_SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
    * Creating Document
          L_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
                                        I_TYPE  = 'RAW'
                                        I_TEXT  = I_CONTENT[]
                                        I_SUBJECT = 'Automated HRIS (SAP) Report' ).
    DATA: W_PERNR LIKE I_PERNR.
    * Preparing contents of attachment with Change Log
          PERFORM PREPARE_ATTACHMENT.
          DATA: compressed like solisti1 occurs 10 with header line.
    DATA: decompressed like solisti1 occurs 10 with header line.
          CALL FUNCTION 'TABLE_COMPRESS'
    *   IMPORTING
    *     COMPRESSED_SIZE       =
                        TABLES
    *      in                    = eerec
                          in                    = i_attach
                          out                   = compressed.
          CALL FUNCTION 'TABLE_DECOMPRESS'
            TABLES
              in  = compressed
              out = decompressed.
          DESCRIBE TABLE decompressed LINES L_LINES.
    * Size to multiplied by 2 for UNICODE enabled systems
          L_SIZE = L_LINES * 2 * 255.
    * Adding Attachment
          CALL METHOD L_DOCUMENT->ADD_ATTACHMENT
            EXPORTING
              I_ATTACHMENT_TYPE    = C_EXT
              I_ATTACHMENT_SIZE    = L_SIZE
              I_ATTACHMENT_SUBJECT = 'Hr Details'
    *          i_att_content_hex    = i_attach[].
              I_ATT_CONTENT_TEXT   = decompressed[].
    *      DESCRIBE TABLE I_MARC LINES L_LINES.
    * Size to multiplied by 2 for UNICODE enabled systems
    *      L_SIZE = L_LINES * 2 * 255.
    ** Adding Attachment
    *      CALL METHOD L_DOCUMENT->ADD_ATTACHMENT
    *        EXPORTING
    *          I_ATTACHMENT_TYPE    = C_EXT
    *          I_ATTACHMENT_SIZE    = L_SIZE
    *          I_ATTACHMENT_SUBJECT = 'MARC Details'
    *          I_ATT_CONTENT_HEX    = I_ATTACH1[].
    **          i_att_content_text   = i_attach1[].
    * Add document to send request
          CALL METHOD L_SEND_REQUEST->SET_DOCUMENT( L_DOCUMENT ).
          DATA:LR_SENDER TYPE REF TO IF_SENDER_BCS,
               LR_SEND TYPE REF TO CL_BCS.
    * Preparing the sender object
    *      LR_SENDER = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( sy-uname ).
          DATA: L1_UNAME TYPE SY-UNAME.
          L1_UNAME = SY-UNAME.
          LR_SENDER = CL_SAPUSER_BCS=>CREATE( L1_UNAME ).
    * Setting the sender
          CALL METHOD L_SEND_REQUEST->SET_SENDER
            EXPORTING
              I_SENDER = LR_SENDER.
    * E-Mail
          LOOP AT P_EADDR.
            TRANSLATE P_EADDR-LOW TO LOWER CASE.
            L_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( P_EADDR-LOW ).
            CALL METHOD L_SEND_REQUEST->ADD_RECIPIENT
              EXPORTING
                I_RECIPIENT  = L_RECIPIENT
                I_EXPRESS    = 'U'
                I_COPY       = ' '
                I_BLIND_COPY = ' '
                I_NO_FORWARD = ' '.
            IF SY-SUBRC EQ 0.
              WRITE:/'** SUCCESS:  Email Sent to', P_EADDR-LOW COLOR COL_NORMAL.
            ELSE.
              WRITE:/'** ERROR: Failed to send Email to',P_EADDR-LOW COLOR COL_NEGATIVE .
            ENDIF.
          ENDLOOP.
    *Trigger E-Mail immediately
          L_SEND_REQUEST->SET_SEND_IMMEDIATELY( ' ' ).
          CALL METHOD L_SEND_REQUEST->SEND( ).
          COMMIT WORK.
        CATCH CX_DOCUMENT_BCS INTO L_BCS_EXCEPTION.
        CATCH CX_SEND_REQ_BCS INTO L_SEND_EXCEPTION.
        CATCH CX_ADDRESS_BCS  INTO L_ADDR_EXCEPTION.
      ENDTRY.
    *&      Form  PREPARE_ATTACHMENT
    FORM PREPARE_ATTACHMENT .
      FIELD-SYMBOLS: <LFS_TABLE>,    " Internal table structure
                     <LFS_CON>.      " Field Content
      DATA: L_TEXT TYPE CHAR1024.     " Text content for mail attachment
      DATA: L_CON TYPE STRING. "(50) TYPE c.        " Field Content in character format
      DATA: L_STR TYPE STRING,
            L_STR1 TYPE STRING.
    *data: w_pernr type TABLE OF I_PERNR.
      DATA: LS_SOLIX TYPE SOLIX.
    *  CONCATENATE 'PERNR' 'FIRST NAME' 'Last Name' C_CR INTO L_TEXT SEPARATED BY '|'.
    *  append l_text to i_attach.
    *  clear l_text.
    * Columns to be tab delimeted
      LOOP AT I_PERNR ASSIGNING <LFS_TABLE>.
        DO.
          ASSIGN COMPONENT SY-INDEX OF STRUCTURE <LFS_TABLE>
                 TO <LFS_CON>.
          IF SY-SUBRC NE 0.
            CONCATENATE C_CR L_TEXT INTO L_TEXT.
    *        CONCATENATE l_str c_cr l_text INTO l_str.
    *        ls_solix-line = l_text.
    *        APPEND ls_solix TO i_attach.
            APPEND L_TEXT TO I_ATTACH.
            EXIT.
          ELSE.
            CLEAR: L_CON.
            MOVE <LFS_CON> TO L_CON.
            CONDENSE L_CON.
            IF SY-INDEX = 1.
              CLEAR: L_TEXT.
              MOVE L_CON TO L_TEXT.
            ELSE.
              CONCATENATE L_TEXT L_CON INTO L_TEXT
                 SEPARATED BY C_TAB.
            ENDIF.
          ENDIF.
        ENDDO.
      ENDLOOP.
    *  i_attach1[] = i_attach[].
    ENDFORM.                    " PREPARE_ATTACHMENT
    Please if any one having 6.0 version please upload it and see..
    Regards
    Sas

    Hi ,
    Did you downloaded from  SOST  using the display icon and inside that 4th tab for attachment ....
    and see?
    Regards
    sas
    pS: THE FIRST page is not allowing the spaces in sdn...
    i am getting o/p as
    pernr vochn norna
    .........0001 f0001 l0001
    .................0002 F0002 L0002
    .......................0003 F0003 L0003.....
    Please remove dots and understand that is the o/p i am getting in my presenation file
    i just expecting the o/p as told earlier..
    Regards
    sas

  • Send a mail with the class CL_HTTP_CLIENT

    hi,
    i use this program and i would send a mail with a attachment file PDF. I try to use the function module SO_NEW_DOCUMENT_ATT_SEND_API1 but i dont know to translate the data XSTRING to internal table.
    Thank you.
    *& Report  ZYTEST_TRANSFER_URL2                                        *
    REPORT  zytest_transfer_url2                    .
    *- begin of internal data
    TYPE-POOLS: swfxc, icon.
    DATA: l_http_client TYPE REF TO if_http_client.
    DATA: l_url TYPE string.
    DATA: l_code TYPE sy-subrc.
    DATA: l_code_string TYPE string.
    DATA: l_message_string TYPE string.
    DATA: lt_http_fields TYPE tihttpnvp.
    DATA: l_http_field_wa TYPE ihttpnvp.
    DATA: l_char_header(40) TYPE c.
    DATA: l_body_string TYPE string.
    DATA : line TYPE string.
    DATA: result_tab TYPE TABLE OF string,
    result_str TYPE string.
    *- end of internal data
    DATA: lv_contents TYPE string.
    DATA: lv_location TYPE string.
    *- begin of parameters
    PARAMETERS: url TYPE swc_value.
    PARAMETERS : receiver TYPE somlreci1-receiver LOWER CASE.
    *- end of parameters
    START-OF-SELECTION.
      PERFORM main.
    *& Form main
    text
    FORM main.
    PERFORM get_contents USING lv_contents.
    *- Create the HTTP-Client
      l_url = url.
    l_proxy_host =
    l_proxy_service =
      CALL METHOD cl_http_client=>create_by_url
      EXPORTING
      url = l_url
    proxy_host = l_proxy_host
    proxy_service = l_proxy_service
      IMPORTING
      client = l_http_client
      EXCEPTIONS
      argument_not_found = 1
      plugin_not_active = 2
      internal_error = 3
      OTHERS = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    *- send the http post
      CALL METHOD l_http_client->send
        EXCEPTIONS
          http_communication_failure = 1
          http_invalid_state         = 2.
      IF sy-subrc <> 0.
        WRITE: / icon_red_light AS ICON.
        CALL METHOD l_http_client->get_last_error
          IMPORTING
            code    = l_code
            MESSAGE = l_message_string.
        CALL METHOD l_http_client->close.
        l_code_string = l_code.
        CONCATENATE 'HTTP-Send: RC=' l_code_string              "#EC NOTEXT
        INTO l_code_string .
        CONCATENATE l_code_string l_message_string
        INTO l_message_string SEPARATED BY space.
        PERFORM print_string USING l_message_string.
        EXIT.
      ENDIF.
    *- receive the result of http post
      CALL METHOD l_http_client->receive
        EXCEPTIONS
          http_communication_failure = 1
          http_invalid_state         = 2.
      IF sy-subrc <> 0.
        WRITE: / icon_red_light AS ICON.
        CALL METHOD l_http_client->get_last_error
          IMPORTING
            code    = l_code
            MESSAGE = l_message_string.
        CALL METHOD l_http_client->close.
        l_code_string = l_code.
        CONCATENATE 'HTTP-Receive: RC=' l_code_string           "#EC NOTEXT
        INTO l_code_string .
        CONCATENATE l_code_string l_message_string
        INTO l_message_string SEPARATED BY space.
        PERFORM print_string USING l_message_string.
        EXIT.
      ENDIF.
    *- print the results
      CALL METHOD l_http_client->response->get_status
        IMPORTING
          code = l_code.
      IF l_code < 300.
    HTTP-codes: 100 - 199 = informations
    HTTP-codes: 200 - 299 = client-request successful (200 = OK)
        WRITE: / icon_green_light AS ICON.
      ELSE.
    HTTP-codes: 300 - 399 = redirected; further actions required
    HTTP-codes: 400 - 499 = client-request incomplete
    HTTP-codes: 500 - 599 = server errors
        WRITE: / icon_red_light AS ICON.
      ENDIF.
    *-- get the http header fields
      CALL METHOD l_http_client->response->get_header_fields
        CHANGING
          fields = lt_http_fields.
      LOOP AT lt_http_fields INTO l_http_field_wa.
        l_char_header = l_http_field_wa-name.
        WRITE: / l_char_header.
        l_char_header = l_http_field_wa-value.
        WRITE: l_char_header.
      ENDLOOP.
      WRITE: / sy-uline.
    *- get the body
      DATA: lv_bin_contents TYPE xstring.
      lv_bin_contents = l_http_client->response->get_data( ).
      PERFORM save_file USING lv_bin_contents.
    ENDFORM. "main
    *& Form print_string
    FORM print_string USING p_string TYPE string.
      REFRESH result_tab.
      SPLIT p_string AT cl_abap_char_utilities=>cr_lf INTO TABLE result_tab.
      LOOP AT result_tab INTO result_str.
        WRITE:/ result_str.
      ENDLOOP.
    ENDFORM. " print_string
    *& Form save_file
    text
    FORM save_file USING lv_bin_contents.
      DATA: save_file(1000) TYPE c VALUE '/tmp/test3.pdf'.
      DATA: lv_file TYPE localfile.
      DATA : g_file(80).
      g_file = url.
      DO.
        SHIFT g_file LEFT UP TO '/'.
        IF sy-subrc NE 0.
          EXIT.
        ENDIF.
        SHIFT g_file LEFT.
      ENDDO.
      SHIFT g_file RIGHT UP TO '.'.
      SHIFT g_file RIGHT.
      lv_file = save_file.
      OPEN DATASET lv_file FOR OUTPUT IN BINARY MODE.
      IF sy-subrc NE 0.
        WRITE:'SY-SUBRC :',sy-subrc.
    MESSAGE i000 WITH text-014. "'File Directory not found'.
        EXIT.
      ENDIF.
      TRANSFER lv_bin_contents TO lv_file.
      CLOSE DATASET lv_file.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      IF sy-subrc EQ 0.
    MESSAGE i000 WITH text-012."'Successfully downloaded to Application
    server'.
        EXIT.
      ENDIF.
    ENDFORM. "save_file

    hi,
    i use this program and i would send a mail with a attachment file PDF. I try to use the function module SO_NEW_DOCUMENT_ATT_SEND_API1 but i dont know to translate the data XSTRING to internal table.
    Thank you.
    *& Report  ZYTEST_TRANSFER_URL2                                        *
    REPORT  zytest_transfer_url2                    .
    *- begin of internal data
    TYPE-POOLS: swfxc, icon.
    DATA: l_http_client TYPE REF TO if_http_client.
    DATA: l_url TYPE string.
    DATA: l_code TYPE sy-subrc.
    DATA: l_code_string TYPE string.
    DATA: l_message_string TYPE string.
    DATA: lt_http_fields TYPE tihttpnvp.
    DATA: l_http_field_wa TYPE ihttpnvp.
    DATA: l_char_header(40) TYPE c.
    DATA: l_body_string TYPE string.
    DATA : line TYPE string.
    DATA: result_tab TYPE TABLE OF string,
    result_str TYPE string.
    *- end of internal data
    DATA: lv_contents TYPE string.
    DATA: lv_location TYPE string.
    *- begin of parameters
    PARAMETERS: url TYPE swc_value.
    PARAMETERS : receiver TYPE somlreci1-receiver LOWER CASE.
    *- end of parameters
    START-OF-SELECTION.
      PERFORM main.
    *& Form main
    text
    FORM main.
    PERFORM get_contents USING lv_contents.
    *- Create the HTTP-Client
      l_url = url.
    l_proxy_host =
    l_proxy_service =
      CALL METHOD cl_http_client=>create_by_url
      EXPORTING
      url = l_url
    proxy_host = l_proxy_host
    proxy_service = l_proxy_service
      IMPORTING
      client = l_http_client
      EXCEPTIONS
      argument_not_found = 1
      plugin_not_active = 2
      internal_error = 3
      OTHERS = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    *- send the http post
      CALL METHOD l_http_client->send
        EXCEPTIONS
          http_communication_failure = 1
          http_invalid_state         = 2.
      IF sy-subrc <> 0.
        WRITE: / icon_red_light AS ICON.
        CALL METHOD l_http_client->get_last_error
          IMPORTING
            code    = l_code
            MESSAGE = l_message_string.
        CALL METHOD l_http_client->close.
        l_code_string = l_code.
        CONCATENATE 'HTTP-Send: RC=' l_code_string              "#EC NOTEXT
        INTO l_code_string .
        CONCATENATE l_code_string l_message_string
        INTO l_message_string SEPARATED BY space.
        PERFORM print_string USING l_message_string.
        EXIT.
      ENDIF.
    *- receive the result of http post
      CALL METHOD l_http_client->receive
        EXCEPTIONS
          http_communication_failure = 1
          http_invalid_state         = 2.
      IF sy-subrc <> 0.
        WRITE: / icon_red_light AS ICON.
        CALL METHOD l_http_client->get_last_error
          IMPORTING
            code    = l_code
            MESSAGE = l_message_string.
        CALL METHOD l_http_client->close.
        l_code_string = l_code.
        CONCATENATE 'HTTP-Receive: RC=' l_code_string           "#EC NOTEXT
        INTO l_code_string .
        CONCATENATE l_code_string l_message_string
        INTO l_message_string SEPARATED BY space.
        PERFORM print_string USING l_message_string.
        EXIT.
      ENDIF.
    *- print the results
      CALL METHOD l_http_client->response->get_status
        IMPORTING
          code = l_code.
      IF l_code < 300.
    HTTP-codes: 100 - 199 = informations
    HTTP-codes: 200 - 299 = client-request successful (200 = OK)
        WRITE: / icon_green_light AS ICON.
      ELSE.
    HTTP-codes: 300 - 399 = redirected; further actions required
    HTTP-codes: 400 - 499 = client-request incomplete
    HTTP-codes: 500 - 599 = server errors
        WRITE: / icon_red_light AS ICON.
      ENDIF.
    *-- get the http header fields
      CALL METHOD l_http_client->response->get_header_fields
        CHANGING
          fields = lt_http_fields.
      LOOP AT lt_http_fields INTO l_http_field_wa.
        l_char_header = l_http_field_wa-name.
        WRITE: / l_char_header.
        l_char_header = l_http_field_wa-value.
        WRITE: l_char_header.
      ENDLOOP.
      WRITE: / sy-uline.
    *- get the body
      DATA: lv_bin_contents TYPE xstring.
      lv_bin_contents = l_http_client->response->get_data( ).
      PERFORM save_file USING lv_bin_contents.
    ENDFORM. "main
    *& Form print_string
    FORM print_string USING p_string TYPE string.
      REFRESH result_tab.
      SPLIT p_string AT cl_abap_char_utilities=>cr_lf INTO TABLE result_tab.
      LOOP AT result_tab INTO result_str.
        WRITE:/ result_str.
      ENDLOOP.
    ENDFORM. " print_string
    *& Form save_file
    text
    FORM save_file USING lv_bin_contents.
      DATA: save_file(1000) TYPE c VALUE '/tmp/test3.pdf'.
      DATA: lv_file TYPE localfile.
      DATA : g_file(80).
      g_file = url.
      DO.
        SHIFT g_file LEFT UP TO '/'.
        IF sy-subrc NE 0.
          EXIT.
        ENDIF.
        SHIFT g_file LEFT.
      ENDDO.
      SHIFT g_file RIGHT UP TO '.'.
      SHIFT g_file RIGHT.
      lv_file = save_file.
      OPEN DATASET lv_file FOR OUTPUT IN BINARY MODE.
      IF sy-subrc NE 0.
        WRITE:'SY-SUBRC :',sy-subrc.
    MESSAGE i000 WITH text-014. "'File Directory not found'.
        EXIT.
      ENDIF.
      TRANSFER lv_bin_contents TO lv_file.
      CLOSE DATASET lv_file.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      IF sy-subrc EQ 0.
    MESSAGE i000 WITH text-012."'Successfully downloaded to Application
    server'.
        EXIT.
      ENDIF.
    ENDFORM. "save_file

  • 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 create  a procedure to send a mail if the Database is down?

    Hi,
    I have created the below procedure to send a mail if the count is less than 1300. It scheduled daily @ 15 30 hrs. Its fine.
    CREATE OR REPLACE procedure SCOTT.hrsmail
    is
    v_count number;
    begin
    Select count(*) into v_count from emp;
    if v_count < 1300
    then
    UTL_MAIL.send(sender => '[email protected]',
    recipients => '[email protected]',
    cc => '[email protected]',
    bcc => '[email protected]',
    subject => 'Testing the UTL_MAIL Package',
    message => 'If you get this, UTL_MAIL package
    else
    null; --what you want to do here
    end if ;
    end;
    Sometime the Database is down, so the job is not running.
    How to create a procedure to send a mail if the database is down?
    Pls help me. Its highly appreciated.
    Thanks
    Nihar

    nihar wrote:
    How to create a procedure to send a mail if the database is down?And what if the database is up, but the network down? Or the database up and mail server down? Or mail server undergoing maintenance?
    There are loads of "+What if's+" - and in that respect, playing "+What if database is down..+" in this case does not make any sense. You do not use the database to monitor its own up/down status. You do not rely just on SMTP as notification protocol that the database is down.
    The correct approach would be using something like SNMP as the monitoring protocol. A monitoring system that can process SNMP and perform some basic root cause analysis (e.g. network to the database server down, database server status unknown). And this system supporting notification methods like SMTP, SMS and so on.

  • PO output type to send a mail  to the user along with PO output as PDF file

    Hi Friends,
    I have one requirement from client.
    Client wants the PO output to be converted to PDF format and sent to User while doing the PO release through e-mail. Can anybody guide me how to Configure a New Output Type and convert the PO output into PDF and send to User through e-mail.
    Thanks
    Nazer

    This can be done with the standard form itself.
    first find out the output type u r using.
    Then goto T-code NACE and then choose EF- purchase order and then select the output type u r using.
    Then goto the 'processing Routines' at the lefe side of the screen.
    There u can find out the output forms for this output typr u r using. Here add 'Simple mail-7' in the list and then give the program name and the smartform or the script u r using.
    We can also give the mail texts for this output form.
    After that goto ME22N and then choose the 'Messages' tab and then click the simple mail and in the 'communication method' kindly provide the mail id for which the PO mail has to be sent.
    And then the mail can be viewed in the inbox of the recipient.
    in this way we can sent the PO mail to the corresponding mail address,.
    I guess this will solve ur issue.
    Thanks and Regards
    Siva
    Edited by: Sivaprakash R on Apr 20, 2009 1:00 PM
    Edited by: Sivaprakash R on Apr 20, 2009 1:00 PM

  • 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

  • Need an enhancement after releasing a PO Need to send a mail to vendor

    Hi all,
              I am having a requirement that, need to send a mail and attachment whenever a PO get released.
    Can anyone help to find the enhancement for to write the code to send a mail to vendor.
    Regards.
    Ranganadh.

    Hi,
    To send a mail when a new PO is created.
    can be achievd by using  class cl_bcs and BADI method
    IF_EX_ME_PROCESS_PO_CUST~POST of BADI ME_PEOCESS_PO_CUST.
    We can aslo configure the OUTPUT TYPE as MAIL in transaction NACE. This is usually doen by the Functional consultant.
    Pls look into these exapmles which clearly explains abt the process of sending a  mail-
    Sending Mail using class cl_bcs
    Re: Mail sending program
    Re: SCOT and FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    Reward if helpful.
    Best Wishes,
    Chandralekha

Maybe you are looking for

  • How can i change the color of menu shortcuts like in photoshop?

    Hello! In Photoshop there's this nice feature in which you can edit every shortcut (like open file, close, palettes, etc.) of the menus (file, edit, etc.) so they have a color and they're easily recognisable. How can I do the same on other mac progra

  • Analog to Digital VI

    Hi  I am using analog to digital converter VI. In that VI, I see all parameters except sample rate. An ADC should always come with sample rate like 10KSPS,1MSPS. Can you tell me how to control sample rate of ADC. I have attached snapshot of my code.

  • Flash slides not showing up

    I have a slide show done in Flash CS3 that is a small inset on the home page of a site. Shows up fine in Firefox, does not show up at all in Explorer. Suggestions? Thanks

  • Site SSL works on Chrome, Safari, and FF for Linux and OS-X, but not FF for Windows 7 (or any Android browser)

    I am setting up a website with SSL: https://coalitionportelgin.ca The SSL connection works (and intermediate certificates are retrieved) in Chrome on Linux, OS-X, and Windows 7; ChromeOS; Firefox (18.0) on OS-X and Linux; and Safari on OS-X, iOS, and

  • Packaging in JAR makes JavaMail not work

    I have simple code (virtually identical to the demo code that comes with JavaMail 1.3) to send an email with an attachment that works fine until i package it in a JAR file and try and use javaw to run it. I have included the mail.jar and activation.j