How to send mail through java program in solaris server

hi
i am writing java code to send the mail using my company SMTP
,the program is working fine when i run and deploy in windows environment
but at the same time when i deploy the war to sun solaris server ,it is not working
and throwing the Error saying
java.lang.Exception: Invalid Addresses; nested exception is:      javax.mail.SendFailedException: 553 sorry, that domain isn't allowed to be relayed thru this MTA without authentication #5.7.1     at jsp.SendMail._jspService(_SendMail.java:137)
i am using the Authentication also using user id and password of same domain and it is able to authenticate
in windows but not in Solaris
where i am making mistake plz
guide.
Saurabh

thanks Alan
but i think there is some other problem because same code is
working when i am using in windows as well as i am using authentication method
also but it is not working when running in Solaris Environment
here is the code i am using to send the mail
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.mycompany.com");//smtp protocol for IIBF
props.put("mail.smtp.starttls.enable","true");//setting start TLS to be true
props.put("mail.smtp.auth", "true");// authentication is false
props.put("mail.smtp.port", port);//setting the port number it can be either 25 or 587
props.put("mail.smtp.username", "noreply");
props.put("mail.smtp.password","noreply");
props.put("mail.debug", "true");
Authenticator auth = new SMTPAuthenticator();
Session session1 = Session.getDefaultInstance(props);
java.util.Properties sessionProperties = new java.util.Properties();
sessionProperties.put("mail.smtp.auth", "true");
message.setFrom(new javax.mail.internet.InternetAddress(From ,"name"));
message.addRecipient(javax.mail.Message.RecipientType.TO, new javax.mail.internet.InternetAddress(To));
message.setText(TextCo);
message.setSubject(subject);
message.setContent(boyd, "text/plain");
message.reply(true);
Transport trans = session1.getTransport("smtp");
trans.connect(SMTP_HOST_NAME, SMTP_AUTH_USER, SMTP_AUTH_PWD);
boolean ddd = trans.isConnected();
message.saveChanges();
trans.sendMessage(message, message.getAllRecipients());
above code is working properly in windows but not in Solaris
plz guide what next to do
thankx in advance
saurabh

Similar Messages

  • How to send sms through java program?

    hi,
    i am trying to send sms through java program.i am usining ubuntu 6.04.i am using modem MC35i.i use the jSMSEnjine.jar and rxtxcomm.jar.
    these are the following program.
    import org.jsmsengine.*;
    import java.util.*;
    class SendMessage
         public static void main(String[] args)
              int status;
              // Create jSMSEngine service.
         CService srv = new CService("Com2",9600);
              //CService srv = new CService("COM2",9600);
              System.out.println();
              System.out.println("SendMessage(): sample application.");
              System.out.println(" Using " + srv._name + " " + srv._version);
              System.out.println();
              try
                   //     Initialize service.     
                   srv.initialize();
                   Thread thread =Thread.currentThread();
                   thread.sleep(1000);
                   System.out.println(srv);
                   //     Set the cache directory.
                   srv.setCacheDir(".\\");
                   //     Set the phonebook.
                   //     srv.setPhoneBook("../misc/phonebook.xml");
                   //     Connect to GSM device.
                   status = srv.connect();
                   //     Did we connect ok?
                   int st=CService.ERR_OK;
                   System.out.println(st);
                   System.out.println(status);
                   if (status == CService.ERR_OK)
                        //     Set the operation mode to PDU - default is ASCII.
                        srv.setOperationMode(CService.MODE_PDU);
                        // Set the SMSC number (set to default).
                        srv.setSmscNumber("");
                        //     Print out GSM device info...
                        System.out.println("Mobile Device Information: ");
                        System.out.println("     Manufacturer : " + srv.getDeviceInfo().getManufacturer());
                        System.out.println("     Model : " + srv.getDeviceInfo().getModel());
                        System.out.println("     Serial No : " + srv.getDeviceInfo().getSerialNo());
                        System.out.println("     IMSI : " + srv.getDeviceInfo().getImsi());
                        System.out.println("     S/W Version : " + srv.getDeviceInfo().getSwVersion());
                        System.out.println("     Battery Level : " + srv.getDeviceInfo().getBatteryLevel() + "%");
                        System.out.println("     Signal Level : " + srv.getDeviceInfo().getSignalLevel() + "%");
                        //     Create a COutgoingMessage object and dispatch it.
                        //     *** Please update the phone number with one of your choice ***
    // String smsLengthTest="Hi"+"\nTesting is going on.Test for sending unlimited number of charecter.So you will get N number of SMS.Initially I trancate the whole string by 70 charecter.Later I will put it upto 90 charecter.Some chararecter should kept for header portion.I don't know the total number.It is just test.If you got the sms u should appreciate me...This is Ripon...I have written sms program";
    String smsLengthTest="Hi\n"+"This is Govindo";
    int mao=smsLengthTest.length();
    System.out.println("Length of sms :"+mao);
    String smsNo="9433314095";
    smsNo="+91"+smsNo;
    if(mao<70)
    COutgoingMessage msg = new COutgoingMessage(smsNo,smsLengthTest);
    //     Character set is 7bit by default - lets make it UNICODE :)
    //     We can do this, because we are in PDU mode (look at line 63). When in ASCII mode,
    //          this does not make ANY difference...
    msg.setMessageEncoding(CMessage.MESSAGE_ENCODING_UNICODE);
    if (srv.sendMessage(msg) == CService.ERR_OK) System.out.println("Message Sent!");
    else System.out.println("Message Failed!");
    else
    // COutgoingMessage msg = new COutgoingMessage(smsNo,smsLengthTest);
    // LinkedList messageList;
    // messageList = new LinkedList();
    // messageList.add(msg);
    // LinkedList maooo=new LinkedList();
    // maooo=srv.splitLargeMessages(messageList);
    int sizelength=0;
    int counter=0;
    sizelength=smsLengthTest.length();
    System.out.println("SMS length :"+sizelength);
    int smsCntr=sizelength/70;
    System.out.println("smsCntr :"+smsCntr);
    counter=smsCntr+1;
    int j=70;
    int k=0;
    try
    for(int i=0;i<smsCntr;i++)
    String test="";
    test=test+i;
    test=smsLengthTest.substring(k,j);
    System.out.println(test);
    System.out.println(test.length());
    COutgoingMessage msg = new COutgoingMessage(smsNo, test);
    System.out.println("hi this is suman" + smsNo);
    //     Character set is 7bit by default - lets make it UNICODE :)
    //     We can do this, because we are in PDU mode (look at line 63). When in ASCII mode,
    //          this does not make ANY difference...
    msg.setMessageEncoding(CMessage.MESSAGE_ENCODING_UNICODE);
    if (srv.sendMessage(msg) == CService.ERR_OK) System.out.println("Message Sent!");
    else System.out.println("Message Failed!");
    k=k+70;
    j=j+70;
    catch(Exception e)
    System.out.println("Error...1");
    e.printStackTrace();
    e.getMessage();
    String lastPortion=smsLengthTest.substring(k);
    System.out.println(lastPortion);
    COutgoingMessage msg = new COutgoingMessage(smsNo, lastPortion);
    //     Character set is 7bit by default - lets make it UNICODE :)
    //     We can do this, because we are in PDU mode (look at line 63). When in ASCII mode,
    //          this does not make ANY difference...
    msg.setMessageEncoding(CMessage.MESSAGE_ENCODING_UNICODE);
    if (srv.sendMessage(msg) == CService.ERR_OK) System.out.println("Message Sent!");
    else System.out.println("Message Failed!");
                        // Disconnect from GSM device.
                        srv.disconnect();
                   else System.out.println("Connection to mobile failed, error: " + status);
              catch (Exception e)
                   e.printStackTrace();
              System.exit(0);
    the error is:
    SendMessage(): sample application.
    Using jSMSEngine API 1.2.6 (B1)
    org.jsmsengine.CService@addbf1
    0
    -101
    Connection to mobile failed, error: -101
    please help me,its very urgent.

    come back in about 5 years, we may have time for you by then.
    In the meantime, how about contacting the people who wrote that library and asking them nicely for help (rather than trying to order people to drop whatever they're doing and jump through hoops to accommodate your every wish as you're doing here)?

  • Send mail through Java program. ERROR javax.mail.MessagingException: [EOF]

    Hi,
    i've a java Mail program which will send the mail thro smtp server.
    when i try to execute this program im getting the error javax.mail.MessagingException: [EOF]
    i've attached both code & error.
    while running the program need to give the arguments
    ex : java SendMail smtpserver frommailid tomailid subject body
    please provide me the solution.
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    public class SendMail {
         public static void main(String[] args) {
              try
         String smtpServer=args[0];
         String to=args[1];
         String from=args[2];
         String subject=args[3];
         String body=args[4];
         send(smtpServer, to, from, subject, body);
         catch (Exception ex)
         System.out.println("Usage: java SendMail"
         +" smtpServer toAddress fromAddress subjectText bodyText");
         System.exit(0);
         public static void send(String smtpServer, String to, String from
                   , String subject, String body)
                   try
                   Properties props = System.getProperties();
                   props.put("mail.smtp.host", smtpServer);
                   Session session = Session.getDefaultInstance(props, null);
                   Message msg = new MimeMessage(session);
                   msg.setFrom(new InternetAddress(from));
                   msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));
                   msg.setSubject(subject);
                   msg.setText(body);
                   msg.setSentDate(new Date());
                   System.out.println("test 1--");
                   Transport.send(msg);
                   System.out.println("test 2--");
                   System.out.println("Message sent OK.");
                   catch (Exception ex)
                   ex.printStackTrace();
    thanks for the help in advance.
    regs
    lal.

    I ran into a similar error today. I fixed it by setting up SMTP authentication because my ISP's help pages said that they would allow only SMTP authentication.
    Here is what I did:
    Transport transport =
    mailConnection.getTransport("smtp");
    transport.connect(
    "hostname", "email", "password");
    Transport.send(msg);
    I also passed the following property while creating the session:
    props.put("mail.smtp.auth", "true");
    finally turning on debug helped:
    session.setDebug(true);
    session.setDebugOut(null);
    Hope this helps

  • How to send mail using jsp program

    am very new to jsp and doing my final year project. i need to send mails using my jsp program.can anyone say wht to do that is wht to include to send mails using jsp program. n also a sample code to send mail using jsp program.
    Thanx in advance

    Use below script.
    <%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
    <%
    Properties props = new Properties();
    props.put("mail.smtp.host", "mailserver.com");
    Session s = Session.getInstance(props,null);
    InternetAddress from = new InternetAddress("[email protected]");
    InternetAddress to = new InternetAddress([email protected]");
    MimeMessage message = new MimeMessage(s);
    message.setFrom(from);
    message.addRecipient(Message.RecipientType.TO, to);
    message.setSubject("Your subject");
    message.setText("Your text");
    Transport.send(message);
    %>{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to send SMS from Java program?

    Hello,
    I want to know, how can I send SMS from Java program.I dont have any idea about SMS gateways. Can any one give me Sample code for sending the SMSs from Java Program.
    Thanks,
    -BR

    hi,
    refer javamail concepts
    http://www.google.co.in/search?q=javamail+simple+example&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

  • How to send mail in PL/SQL using exchange server details.

    Hi Experts,
    Business user has provided us the exchange server details to send mails.How can I send mails thru PL/SQL using exchange server details.

    user595740 wrote:
    Business user has provided us the exchange server details to send mails.How can I send mails thru PL/SQL using exchange server details.Basic answer - not easily.
    Oracle supports the standard application protocol SMTP - it does not support a proprietary protocol like that used by Exchange that only works on the Windows operating system. It however provides you with the flexibility to code this yourself.
    If you for example use Microsoft MAPI (Mail Application Programming Interface), you can integrate it with PL/SQL using the external procedure (extproc) feature of Oracle.
    In a nutshell, extproc enables you to create PL/SQL wrappers for public DLL calls. I posted sample code that demonstrates this in {message:id=2271919}. The sample code is for calling a DLL interface on HP-UX, but the concept is identical on Windows.

  • How to invoke browser from java program in Solaris ?

    Hi all,
    Is there any way by which a browser can be opened with specific URL, from a java program in solaris OS ?
    In windows I am able to do so by using "rundll32 url.dll,FileProtocolHandler".
    Thanks,
    ngs

    Well, how is a browser normally invoked on Solaris? And have a look at JDIC, maybe it helps you.

  • How to send mail through report??

    hi experts....
    i want to create a report to send an email to department representative when pending PO is created.
    can some1 tell me how is it possible to send an email through report?
    thanks..

    Refer the following programs:
    <b>Mail sent without attachment:</b>
    REPORT Z34332_MAIL.
    * Check the mail in T-code SBWP
    * To check the send mail status T-Code SOST
    data: it_packing_list type table of SOPCKLSTI1,
    wa_packing-list like line of it_packing_list,
    it_receivers type table of SOMLRECI1,
    wa_receivers like line of it_receivers,
    it_mailbody type table of SOLISTI1,
    wa_mailbody like line of it_mailbody.
    data: la_doc type SODOCCHGI1.
    * mail header
    la_doc-OBJ_DESCR = 'HI'.
    * Describe the body of the message
    CLEAR wa_packing-list.
    REFRESH it_packing_list.
    wa_packing-list-transf_bin = space.
    wa_packing-list-head_start = 1.
    wa_packing-list-head_num = 0.
    wa_packing-list-body_start = 1.
    * DESCRIBE TABLE gt_mara LINES wa_packing-list-body_num.
    wa_packing-list-body_num = 1.
    wa_packing-list-doc_type = 'RAW'.
    APPEND wa_packing-list to it_packing_list.
    * Add the recipients email address
    CLEAR wa_receivers.
    REFRESH it_receivers.
    wa_receivers-receiver = 'PCSDEVL'.
    wa_receivers-rec_type = 'U'.
    wa_receivers-com_type = 'INT'.
    wa_receivers-notif_del = 'X'.
    wa_receivers-notif_ndel = 'X'.
    APPEND wa_receivers to it_receivers.
    * Mail Body
    CLEAR wa_mailbody.
    REFRESH it_mailbody.
    wa_mailbody-line = 'How are you.'.
    APPEND wa_mailbody to it_mailbody.
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
    document_data = la_doc
    PUT_IN_OUTBOX = 'X'
    * SENDER_ADDRESS = SY-UNAME
    * SENDER_ADDRESS_TYPE = 'B'
    COMMIT_WORK = 'X'
    * IMPORTING
    * SENT_TO_ALL =
    * NEW_OBJECT_ID =
    * SENDER_ID =
    tables
    packing_list = it_packing_list
    * OBJECT_HEADER =
    * CONTENTS_BIN =
    CONTENTS_TXT = it_mailbody
    * CONTENTS_HEX =
    * OBJECT_PARA =
    * OBJECT_PARB =
    receivers = it_receivers
    EXCEPTIONS
    TOO_MANY_RECEIVERS = 1
    DOCUMENT_NOT_SENT = 2
    DOCUMENT_TYPE_NOT_EXIST = 3
    OPERATION_NO_AUTHORIZATION = 4
    PARAMETER_ERROR = 5
    X_ERROR = 6
    ENQUEUE_ERROR = 7
    OTHERS = 8
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    <b>
    mail with attachment:</b>
    REPORT Z34332_MAIL_WITH_ATTACHMENT1.
    types: begin of t_mara,
    matnr type mara-matnr,
    matkl type mara-matkl,
    mtart type mara-mtart,
    meins type mara-meins,
    end of t_mara.
    data: gt_mara type table of t_mara,
    wa_mara like line of gt_mara,
    it_packing_list type table of SOPCKLSTI1,
    wa_packing_list like line of it_packing_list,
    it_receivers type table of SOMLRECI1,
    wa_receivers like line of it_receivers,
    it_mailbody type table of SOLISTI1,
    wa_mailbody like line of it_mailbody,
    it_attachment type table of SOLISTI1,
    wa_attachment like line of it_attachment.
    data: la_doc type SODOCCHGI1.
    constants:
    con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
    con_cret type c value cl_abap_char_utilities=>CR_LF.
    * get material
    select matnr matkl mtart meins
    into table gt_mara
    from mara
    up to 25 rows.
    * Populate the subject/generic message attributes
    la_doc-obj_langu = sy-langu.
    la_doc-obj_descr = 'Material Details' . "Mail Header
    la_doc-sensitivty = 'F'.
    la_doc-doc_size = 1.
    * Add the recipients email address
    CLEAR wa_receivers.
    REFRESH it_receivers.
    wa_receivers-receiver = 'PCSDEVL'.
    wa_receivers-rec_type = 'U'.
    wa_receivers-com_type = 'INT'.
    wa_receivers-notif_del = 'X'.
    wa_receivers-notif_ndel = 'X'.
    APPEND wa_receivers to it_receivers.
    * Mail Body
    CLEAR wa_mailbody.
    REFRESH it_mailbody.
    wa_mailbody-line = 'Please find the attachment'.
    APPEND wa_mailbody to it_mailbody.
    * Mail attachmwnt
    CLEAR wa_attachment.
    REFRESH it_attachment.
    CONCATENATE 'MATNR' 'MATKL' 'MTART' 'MEINS'
    INTO wa_attachment SEPARATED BY con_tab.
    CONCATENATE con_cret wa_attachment INTO wa_attachment.
    APPEND wa_attachment to it_attachment.
    LOOP AT gt_mara INTO wa_mara.
    CONCATENATE wa_mara-matnr wa_mara-matkl
    wa_mara-mtart wa_mara-meins
    INTO wa_attachment SEPARATED BY con_tab.
    CONCATENATE con_cret wa_attachment INTO wa_attachment.
    APPEND wa_attachment to it_attachment.
    ENDLOOP.
    * Describe the body of the message
    CLEAR wa_packing_list.
    REFRESH it_packing_list.
    wa_packing_list-transf_bin = space.
    wa_packing_list-head_start = 1.
    wa_packing_list-head_num = 0.
    wa_packing_list-body_start = 1.
    wa_packing_list-body_num = 1.
    wa_packing_list-doc_type = 'RAW'.
    APPEND wa_packing_list to it_packing_list.
    * Create attachment notification
    wa_packing_list-transf_bin = 'X'.
    wa_packing_list-head_start = 1.
    wa_packing_list-head_num = 1.
    wa_packing_list-body_start = 1.
    DESCRIBE TABLE it_attachment LINES wa_packing_list-body_num.
    wa_packing_list-doc_type = 'XLS'. " To word attachment change this as 'DOC'
    wa_packing_list-obj_descr = ' '.
    concatenate wa_packing_list-doc_type 'file' into wa_packing_list-OBJ_DESCR
    separated by space.
    wa_packing_list-doc_size = wa_packing_list-body_num * 255.
    APPEND wa_packing_list to it_packing_list.
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
    document_data = la_doc
    PUT_IN_OUTBOX = 'X'
    * SENDER_ADDRESS = SY-UNAME
    * SENDER_ADDRESS_TYPE = 'B'
    COMMIT_WORK = 'X'
    * IMPORTING
    * SENT_TO_ALL =
    * NEW_OBJECT_ID =
    * SENDER_ID =
    tables
    packing_list = it_packing_list
    * OBJECT_HEADER =
    CONTENTS_BIN = it_attachment
    CONTENTS_TXT = it_mailbody
    * CONTENTS_HEX =
    * OBJECT_PARA =
    * OBJECT_PARB =
    receivers = it_receivers
    EXCEPTIONS
    TOO_MANY_RECEIVERS = 1
    DOCUMENT_NOT_SENT = 2
    DOCUMENT_TYPE_NOT_EXIST = 3
    OPERATION_NO_AUTHORIZATION = 4
    PARAMETER_ERROR = 5
    X_ERROR = 6
    ENQUEUE_ERROR = 7
    OTHERS = 8
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.

  • How to send fax using java programming

    i need to send files in my hard disk through fax using java programming.
    i have found on the internet that it is possible to be implemented by using java.comm API and JTAPI. however, i don't know how...does anyone can tell me the details? also, as i know it will be a big project to send fax using such API. is that any other simple way to implement the fax function in java? thx a lot!

    To cse.mahbub:
    Are you aware that you replied to a 5 1/2 year old question?
    Please don't do that. Reply only to current questions.

  • Can anybody help on sending mail through Java Code

    I am trying to send the mail using the java code and I am unable to do it. My code is
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.text.*;
    public class EmailExample {
    public static void main(String[] args)
    Socket smtpSocket;
    DataOutputStream os;
    BufferedReader is;
    Date dDate = new Date();
    DateFormat dFormat = DateFormat.getDateInstance(DateFormat.FULL,Locale.US);
    try
    smtpSocket = new Socket("www.gmail.com",80);
    os = new DataOutputStream(smtpSocket.getOutputStream());
    is = new BufferedReader(new InputStreamReader(smtpSocket.getInputStream()));
    System.out.println("Hi How is this?");
    os.writeBytes("HELLO\r\n");
    // You will add the email address that the server
    // you are using know you as.
    os.writeBytes("MAIL From: <[email protected]>\r\n");
    // Who the email is going to.
    os.writeBytes("RCPT To: <[email protected]>\r\n");
    //IF you want to send a CC then you will have to add this
    //os.writeBytes("RCPT Cc: <[email protected]>\r\n");
    // Now we are ready to add the message and the
    // header of the email to be sent out.
    os.writeBytes("DATA\r\n");
    os.writeBytes("X-Mailer: Via Java\r\n");
    os.writeBytes("DATE: " + dFormat.format(dDate) + "\r\n");
    System.out.println("DATE: " + dFormat.format(dDate) + "\r\n");
    os.writeBytes("From: Me <[email protected]>\r\n");
    os.writeBytes("To: YOU <[email protected]>\r\n");
    //Again if you want to send a CC then add this.
    //os.writeBytes("Cc: CCDUDE <[email protected]>\r\n");
    //Here you can now add a BCC to the message as well
    //os.writeBytes("RCPT Bcc: BCCDude<[email protected]>\r\n");
    String sMessage = "Your subjectline here";
    os.writeBytes("Subject: Your subjectline here\r\n");
    os.writeBytes(sMessage + "\r\n");
    os.writeBytes("\r\n.\r\n");
    os.writeBytes("QUIT\r\n");
    // Now send the email off and check the server reply.
    // Was an OK is reached you are complete.
    String responseline;
    while((responseline = is.readLine())!=null)
    {   System.out.println(responseline);
    if(responseline.indexOf("Ok") != -1)
    break;
    } catch (IOException e) {
    e.printStackTrace();
    It is compiling and runnung properly. Please Help me on this.
    Thanks.
    Satya.

    You're mishandling the responses. You terminate if you don't get an "Ok" string, but that's not how success is defined - you should get a 200 code back, typically with an "OK" (not caps) message.
    It doesn't help that you're ignoring all of the server output after each command, so you never find out if anything goes wrong.
    You're also reinventing a wheel. The JavaMail API exists for this: http://java.sun.com/products/javamail/

  • Issue with sending mail through java stored procedure in Oracle

    Hello
    I am using Oracle 9i DB. I created a java stored procedure to send mail using the code given below. The java class works fine standalone. When its run from Java, mail is sent as desired. But when the java stored procedure is called from pl/sql "Must issue a STARTTLS command first" error is thrown. Please let me know if am missing something. Tried the same code in 11.2.0.2 DB and got the same error
    Error:
    javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. va6sm31201010igc.6
    Code for creating java stored procedure: (T1 is the table created for debugging)
    ==================================================
    create or replace and compile java source named "MailUtil1" AS
    import java.util.Enumeration;
    import java.util.Properties;
    import javax.mail.Message;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    public class MailUtil1 {
    public static void sendMailwithSTARTTLS(String host, //smtp.projectp.com
    String from, //sender mail id
    String fromPwd,//sender mail pwd
    String port,//587
    String to,//recepient email ids
    String cc,
    String subject,
    String messageBody) {
    try{
    Properties props = System.getProperties();
    props.put("mail.smtp.starttls.enable", "True"); // added this line
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.user", from);
    props.put("mail.smtp.password", fromPwd);
    props.put("mail.smtp.port", port);
    props.put("mail.smtp.auth", "true");
    #sql { insert into t1 (c1) values ('1'||:host)};
    Session session = Session.getDefaultInstance(props, null);
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    #sql { insert into t1 (c1) values ('2')};
    InternetAddress[] toAddress = new InternetAddress[1];
    // To get the array of addresses
    for( int i=0; i < toAddress.length; i++ ) { // changed from a while loop
    toAddress[i] = new InternetAddress(to);
    //System.out.println(Message.RecipientType.TO);
    for( int i=0; i < toAddress.length; i++) { // changed from a while loop
    message.addRecipient(Message.RecipientType.TO, toAddress);
    if (cc!=null) {
    InternetAddress [] ccAddress = new InternetAddress[1];
    for(int j=0;j<ccAddress.length;j++){
    ccAddress[j] = new InternetAddress(cc);
    for (int j=0;j<ccAddress.length;j++){
    message.addRecipient(Message.RecipientType.CC, ccAddress[j]);
    message.setSubject(subject);
    message.setText(messageBody);
    message.saveChanges();
    #sql { insert into t1 (c1) values ('3')};
    Enumeration en = message.getAllHeaderLines();
    String token;
    while(en.hasMoreElements()){
    token ="E:"+en.nextElement().toString();
    #sql { insert into t1 (c1) values (:token)};
    token ="ConTyp:"+message.getContentType();
    #sql { insert into t1 (c1) values (:token)};
    token = "Encod:"+message.getEncoding();
    #sql { insert into t1 (c1) values (:token)};
    token = "Con:"+message.getContent();
    #sql { insert into t1 (c1) values (:token)};
    Transport transport = session.getTransport("smtp");
    #sql { insert into t1 (c1) values ('3.1')};
    transport.connect(host, from, fromPwd);
    #sql { insert into t1 (c1) values ('3.2')};
    transport.sendMessage(message, message.getAllRecipients());
    #sql { insert into t1 (c1) values ('3.3')};
    transport.close();
    #sql { insert into t1 (c1) values ('4')};
    catch(Exception e){
    e.printStackTrace();
    String ex= e.toString();
    try{
    #sql { insert into t1 (c1) values (:ex)};
    catch(Exception e1)
    Edited by: user12050615 on Jan 16, 2012 12:18 AM

    Hello,
    Thanks for the reply. Actually I have seen that post before creating this thread. I thought that I could make use of java mail to work around this problem. I created a java class that succesfully sends mail to SSL host. I tried to call this java class from pl-sql through java stored procedure. That did not work
    So, is this not supported in Oracle ? Please note that I have tested this in both 9i and 11g , in both the versions I got the error. You can refer to the code in the above post.
    Thanks
    Srikanth
    Edited by: user12050615 on Jan 16, 2012 12:17 AM

  • Not able to send mail through java

    Hi,
    I am sending an email through java but it gives me exception that Authentication failed exception but I have provided correct credentials
    I have given stack trace as below
    19 Mar 2013 16:32:58,579 614378 [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] ERROR alfaaesar.portal.pages.common.bo.AfCmnCommonBO  – AfCmnCommonBo SendMail Exception:javax.mail.AuthenticationFailedException
         at javax.mail.Service.connect(Service.java:319)
         at alfaaesar.portal.pages.common.bo.AfCmnCommonBO.sendMail(AfCmnCommonBO.java:939)
         at alfaaesar.portal.pages.literature.action.AfLitetatureRequestAndViewAction.InsertLiteratureReqDtlsInAlfaLitHeaderTbl(AfLitetatureRequestAndViewAction.java:619)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at com.sun.el.parser.AstValue.invoke(Unknown Source)
         at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)
         at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:46)
         at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
         at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)
         at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent$1.run(ContextSwitchingComponent.java:92)
         at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent._processPhase(ContextSwitchingComponent.java:361)
         at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent.broadcast(ContextSwitchingComponent.java:96)
         at oracle.adf.view.rich.component.fragment.UIXInclude.broadcast(UIXInclude.java:102)
         at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent$1.run(ContextSwitchingComponent.java:92)
         at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent._processPhase(ContextSwitchingComponent.java:361)
         at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent.broadcast(ContextSwitchingComponent.java:96)
         at oracle.adf.view.rich.component.fragment.UIXInclude.broadcast(UIXInclude.java:96)
         at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
         at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
         at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._invokeApplication(LifecycleImpl.java:889)
         at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:379)
         at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:194)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
         at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
         at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
         at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at alfaaesar.portal.pages.filter.AnonymousSessionFilter.doFilter(AnonymousSessionFilter.java:47)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.portlet.client.adapter.adf.ADFPortletFilter.doFilter(ADFPortletFilter.java:32)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.webcenter.framework.events.dispatcher.EventDispatcherFilter.doFilter(EventDispatcherFilter.java:44)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:205)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:106)
         at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)
         at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
         at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)
         at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:271)
         at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:177)
         at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.wcps.client.PersonalizationFilter.doFilter(PersonalizationFilter.java:75)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.webcenter.content.integration.servlets.ContentServletFilter.doFilter(ContentServletFilter.java:168)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.webcenter.lifecycle.filter.LifecycleLockFilter.doFilter(LifecycleLockFilter.java:151)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:179)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119)
         at java.security.AccessController.doPrivileged(Native Method)
         at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
         at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:442)
         at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
         at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
         at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:139)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
         at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
         at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
         at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)Also given code below in java to send an email .
                    public  Boolean sendMail(String host,String port,String debugFlag,String authFlag, String userId,String password,String fromEmailAddress,String toEmailAddress,String subject,String eMailcontent ) throws MessagingException {
            Boolean sendMailFlag = false;
            Properties props = new Properties();
            props.put("mail.smtp.host", host);
            props.put("mail.smtp.port", port);
            props.put("mail.debug", debugFlag); //Set default to false
            props.put("mail.smtp.auth", authFlag); //Set default to true
            props.put("mail.transport.protocol", "smtp");
            props.put("mail.smtp.sendpartial","true");
           // props.put("mail.smtp.starttls.enable", "true");
            logger.info("Sending Email.......");
            //System.out.println("Sending Email.......");
            try {
                // Instantiatee a message
                final String mailUserId = userId;
                final String mailPassword = password;
               Session mailSession = Session.getDefaultInstance(props, new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(mailUserId, mailPassword);
               MimeMessage msg = new MimeMessage(mailSession);
                msg.setFrom(new InternetAddress(fromEmailAddress));
               String[] to = toEmailAddress.split(",");
               InternetAddress[] addressTo = new InternetAddress[to.length];
                     for (int i = 0; i < to.length; i++)
                         addressTo[i] = new InternetAddress(to);
    msg.setRecipients(Message.RecipientType.TO, addressTo);
    if(JSFUtils.getFromSession("ccEmailAddress")!=null){
    String ccEmailAddress =(String)JSFUtils.getFromSession("ccEmailAddress");
    JSFUtils.removeFromSession("ccEmailAddress");
    String[] cc = ccEmailAddress.split(",");
    InternetAddress[] addressCC = new InternetAddress[cc.length];
    for (int i = 0; i < cc.length; i++)
    addressCC[i] = new InternetAddress(cc[i]);
    msg.setRecipients(Message.RecipientType.CC, addressCC);
    msg.setSubject(subject,"utf-8");
    msg.setSentDate(new Date());
    //msg.setText(eMailcontent);
    msg.setContent(eMailcontent, "text/html; charset=\"utf-8\"");
    if (toEmailAddress.indexOf(',') > 0)
    msg.setRecipients(Message.RecipientType.TO,
    InternetAddress.parse(toEmailAddress));
    else
    msg.setRecipient(Message.RecipientType.TO,
    new InternetAddress(toEmailAddress));
    Transport transport = mailSession.getTransport();
    transport.connect(host,Integer.parseInt(port),userId.trim(),password.trim());
    transport.send(msg);
    transport.close();
    //Send the message
    // Transport.send(msg);
    sendMailFlag = true;
    // System.out.println("mail sent");
    } catch (MessagingException mex) {
    // Prints all nested (chained) exceptions as well
    //logger.info(mex.getMessage());
    logger.error("AfCmnCommonBo SendMail Exception:"+JSFUtils.getStackTrace(mex));
    //mex.printStackTrace();
    sendMailFlag = false;
    return sendMailFlag;
    Edited by: Wecenter Guru on Mar 19, 2013 5:02 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hi All,
    My question got resolved.It is due to the userId and fromEmailAddress was not of same account holder.because of which it is giving relaying denied type exception

  • Reg : Problem in Sending Mail Through Java Code

    Hi All,
    I wrote java code to send email to gmail. But am getting the error as following .
    Error:
    C:\jdevstudio10134\jdk\bin\javaw.exe -client -classpath "C:\jdevstudio10134\jdev\mywork\Prasad\Project1\classes;C:\Program Files\Java\jre1.5.0_14\lib\j2ee.jar" tips.mails.SendMailTest
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
         class javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 995
         at javax.mail.Transport.send0(Transport.java:218)
         at javax.mail.Transport.send(Transport.java:80)
         at tips.mails.SendMail.send(SendMail.java:53)
         at tips.mails.SendMailTest.main(SendMailTest.java:13)
    Process exited with exit code 0.
    Class :
    package tips.mails;
    import java.util.Properties;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.Message.RecipientType;
    import javax.mail.internet.AddressException;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    public class SendMail {
         private String from;
         private String to;
         private String subject;
         private String text;
         public SendMail(String from, String to, String subject, String text){
              this.from = from;
              this.to = to;
              this.subject = subject;
              this.text = text;
         public void send(){
              Properties props = new Properties();
              props.put("mail.smtp.host", "smtp.gmail.com");
              props.put("mail.smtp.port", "995");
              Session mailSession = Session.getDefaultInstance(props);
              Message simpleMessage = new MimeMessage(mailSession);
              InternetAddress fromAddress = null;
              InternetAddress toAddress = null;
              try {
                   fromAddress = new InternetAddress(from);
                   toAddress = new InternetAddress(to);
              } catch (AddressException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              try {
                   simpleMessage.setFrom(fromAddress);
                   simpleMessage.setRecipient(RecipientType.TO, toAddress);
                   simpleMessage.setSubject(subject);
                   simpleMessage.setText(text);
                   Transport.send(simpleMessage);               
              } catch (MessagingException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    ==============================================================================
    Main Class :
    package tips.mails;
    public class SendMailTest {
         public static void main(String[] args) {
              String from = "[email protected]";
              String to = "[email protected]";
              String subject = "Hi Rekha";
              String message = "A test message";
              SendMail sendMail = new SendMail(from, to, subject, message);
              sendMail.send();
    ========================
    Please help me on this .
    Thanks in Advance.

    Hi,
    smtp.gmail.com port is : 587/465
    pop.gmail.com port is : 995
    if u r using ssl connection then use port 465 for smtp.gmail.com. if u r using non-ssl connection means TLS type then u should use port 587 for smtp.gmail.com.
    For any further assistance u can refer to this forum - http://forums.sun.com/forum.jspa?forumID=43 assuming u r using javamail api.

  • Sending mail from java program

    I want to send mail from my java program.
    does anyone have the sample code?

    http://forum.java.sun.com/thread.jsp?forum=31&thread=266116

  • How to send mails through Alerts.

    Hi All,
    I have an requirement to send email to different user periodically after checking some condition in HRMS application.Initially I was trying with the help of JAVA Api.Now while R & D I found that I can do it by using Oracle Alerts.but I dont know How to do this.
    Please Help.
    Regards,
    SHD

    What is the application release?
    Please see "Oracle Alert" manual.
    Oracle Alert User's Guide
    http://download.oracle.com/docs/cd/B25516_18/current/acrobat/115alrug.pdf
    Oracle Alert User's Guide
    http://download.oracle.com/docs/cd/B53825_03/current/acrobat/121alrug.pdf
    Note: Please post similar questions in the appropriate forum.
    EBS General Discussion
    General EBS Discussion
    Thanks,
    Hussein

Maybe you are looking for

  • How to restore the backup files on time capsule after reinstalled the system

    please can someone help me to restore my backups on time capsule after reinstalled the new system. I tried after finished reinstall but it could not find. I also tried with the migration assistant in utilities, it also doesn't work. I always have tim

  • Plan to give my old Nano to a PC non-iTunes owner, but

    I plan to buy a new Nano and give my old one to a friend who has a PC.  I doubt he wants to upload iTunes because we like the same music, so then how can he charge the Nano's battery?  What will happen if he just connects with the USB cord (or whatev

  • Stuck in banding.

    Afternoon, Had a thread going a bit earlier which was deleted as too much info included. I'm still stuck in a band, my lines been stable for over three days, MODS can you please get me out of my banding. Justin ADSL Line Status Connection Information

  • Combobox whose datasource is from an hashmap

    Hello I work on a J2EE/Struts2 project On a jsp, I have a combobox whose datasource is from an hashmap In the action, I can't find how can I get the selected item (the selected key of the object selected in my combobox) in order to load my object (wi

  • RETURN OF MATERIAL FROM CONSIGNMENT AGENT

    Dear Sir, We are a manufacturer of excisable products.Our material when trandferred to the agents godown imposes on us a liability of excise duty as excise duty liability arises on clearance of excisable product from the factory premises.The followin