SendFailedException Error

Hi,
Please take a look at the following source code. It's a simple javamail application to send an Email, got from java.sun.com:
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class SimpleSender {
public static void main (String args[]) throws Exception {
String host = "mail.wishbd.com";
String from = "[email protected]";
String to = "[email protected]";
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");
Transport.send(message);
The code compiles successfully, but when it is run, the following error shows up:
D:\>java SimpleSender
Exception in thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
class javax.mail.SendFailedException: 550 not local host yahoo.com, not a gateway
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at SimpleSender.main(SimpleSender.java:18)
Now, if the "to" field is changed to (say) [email protected], the application runs and the message is sent succesfully to the address. You can check it for yourself by compiling. I have given here the full source code.
What's wrong? Why is the javax.mail.SendFailedException shown up? Could you please, help?
Thanks,
... M. Chisty

Looks like your mail server is set up not to permit relaying, or sending email outside your local domain. See the mail server admin people.
SH

Similar Messages

  • Inquiry on javax.mail.SendFailedException: Invalid Addresses error

    Hi,
    Anyone does have any idea why the following is being encountered during the email authentication process? We are using PeopleSoft application and we have notification functionality which will send a notification email to the users but email not being sent due to an invalid email address but actually the email is active and valid. Below are the logs from SMTP
    Log Start:
    DEBUG SMTP: Sending failed because of invalid destination addresses
    Wed Jul 31 09:38:14 GMT+08:00 2013 RSET
    Wed Jul 31 09:38:14 GMT+08:00 2013 250 2.0.0 Resetting
    Wed Jul 31 09:38:20 GMT+08:00 2013 javax.mail.SendFailedException: Invalid Addresses;
    nested exception is:
    class com.sun.mail.smtp.SMTPAddressFailedException: 550 5.1.1 User unknown
    Wed Jul 31 09:38:20 GMT+08:00 2013 at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1141)
    Wed Jul 31 09:38:20 GMT+08:00 2013 at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:536)
    Wed Jul 31 09:38:20 GMT+08:00 2013 at com.peoplesoft.pt.mcf.mail.MCFOutboundEmail.send(MCFOutboundEmail.java:686)
    Wed Jul 31 09:38:20 GMT+08:00 2013 at com.peoplesoft.pt.mcf.mail.MCFOutboundEmail.send(MCFOutboundEmail.java:854)
    Log End:
    Kindly let us know your thoughts on this.
    Thanks.

    This isn't an authentication problem.  You're sending to an address that your server doesn't know about, so it's rejecting your message.  The error from the server is:
    550 5.1.1 User unknown

  • Error: javax.mail.SendFailedException

    Hi all,
    I have a requirement to send a mail on click of a button. I have written a simple java code using java mail API. But while running the application i am getting
    javax.mail.SendFailedException: Sending failed;  nested exception is: javax.mail.SendFailedException: Invalid Addresses;  nested exception is: javax.mail.SendFailedException: 550 5.7.1 Unable to relay for [email protected]
    If i run the java code as a standalone java application everything is fine. Only in webdynpro application i am getting the above mentioned error.
    My question is do we have to configure any settings in the WAS. If so, can somebody give me a detailed answer how to do the configuration.
    Thanks and Regards,
    Rathna

    I stopped the Antivirus service and checked the application but it doesn't help.
    Here is the code. But the code is working fine.
    // Get system properties
    Properties props = new Properties();
    // Setup mail server
    props.put("mail.pop3.host","myserver");
    props.put("mail.pop3.auth","true");
    Authentication auth = new Authentication("[email protected]","abcd");
                   Session session = Session.getInstance(props,auth);
                   Store store = session.getStore("pop3");
                   store.connect("myserver","[email protected]","abcd");
                   System.out.println("Connected");
                   MimeMessage message =  new MimeMessage(session);
                   message.setFrom(new InternetAddress("[email protected]"));
                   message.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("[email protected]"));
                   message.setSubject("Hello JavaMail Attachment");
                   // create the message part
                   MimeBodyPart messageBodyPart =  new MimeBodyPart();
                   //fill message
                   messageBodyPart.setText("Hi");
                   Multipart multipart = new MimeMultipart();
                   multipart.addBodyPart(messageBodyPart);
                   // Part two is attachment
                   messageBodyPart = new MimeBodyPart();
                   String fileAttachment="D:\Message.txt";
                   DataSource source =  new FileDataSource(fileAttachment);
                   messageBodyPart.setDataHandler(new DataHandler(source));
                   messageBodyPart.setFileName(fileAttachment);
                   multipart.addBodyPart(messageBodyPart);
                   // Put parts in message
                   message.setContent(multipart);
                                  // Send the message
                   javax.mail.Transport.send(message);
                   System.out.println("Mail sent successfully");
                   store.close();

  • Authentication error : sendFailedException :Help needed

    Hello,
    I am trying to make an e-mail client application. I am using the authentication to send the mail. I have applied the required code given in the sample application provided with JavaMail API. But every time the "useAuth" is displaying "false". Can anybody tell me how to inforce the Authentication.
    Thanks.

    Hi,
    I have the same problem.
    Here is my source code
    import java.io.*;
    import java.util.*;
    import java.text.*;
    import java.util.Date;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class EMailClient
         public static void main(String[] args) throws Exception {
                   String recipients = "[email protected]"; //recipients comma separated list of recipients
                   String copies = "";//copies comma separated list of copy-to recipients
                                  String subject = "test";
                                  String bodyText = "test you";
                   String fromAddress ="[email protected]";
                   String incomingMailHost = "pop.sbcglobal.yahoo.com";
                   String outgoingMailHost = "smtp.sbcglobal.yahoo.com";
                   String mailUser = "[email protected]";
                   String mailPwd = "password";
                   EMailClient eClient = new EMailClient(fromAddress,incomingMailHost,outgoingMailHost,mailUser,mailPwd);
    eClient.send(recipients,copies,subject,bodyText);
    public EMailClient (String address,
    String getHost,
    String sendHost,
    String mailUser,
    String mailPwd)
    this.address = address;
    this.getHost = getHost;
    this.sendHost = sendHost;
    this.mailUser = mailUser;
    this.mailPwd = mailPwd;
    protected void send(String recipients,
              String copies,
    String subject,
                   String bodyText) throws MessagingException,
    AddressException,
    NoSuchProviderException,
    IOException
    // create some properties and get the default Session
    Properties props = System.getProperties();
    props.put("mail.smtp.host", sendHost);
    Session session = Session.getDefaultInstance(props,null);
    session.setDebug(false);
    // Log onto pop server first as security protocol may require this
    Store store = session.getStore("pop3");
    store.connect(getHost, mailUser, mailPwd);
    store.close();
    // Create a mime message
    MimeMessage mail = new MimeMessage(session);
    mail.setFrom(new InternetAddress(address));
    StringTokenizer st = new StringTokenizer(recipients,",");
    InternetAddress[] recList = new InternetAddress[st.countTokens()];
    for (int r = 0; st.hasMoreTokens(); r++)
    recList[r] = new InternetAddress(st.nextToken().trim());
    mail.setRecipients(Message.RecipientType.TO, recList);
    st = new StringTokenizer(copies,",");
    InternetAddress[] copyList = new InternetAddress[st.countTokens()];
    for (int c = 0; st.hasMoreTokens(); c++)
    copyList[c] = new InternetAddress(st.nextToken().trim());
    mail.setRecipients(Message.RecipientType.CC, copyList);
    mail.setSubject(subject);
    mail.setText(bodyText);
    mail.setSentDate(new Date());
    // Send the message
    Transport trans = session.getTransport("smtp");
    trans.connect(sendHost, mailUser, mailPwd);
    System.out.println("Conected: "+ trans.isConnected());
    trans.sendMessage(mail, mail.getAllRecipients());
    trans.close();
    The message I got is as follows
    C:\>java EMailClient
    Conected: true
    Exception in thread "main" javax.mail.MessagingException: 530 authentication req
    uired - for help go to http://help.yahoo.com/help/us/sbc/dsl/mail/pop/pop-11.htm
    l
    at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:879)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:599)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:319)
    at EMailClient.send(EMailClient.java:105)
    at EMailClient.main(EMailClient.java:35)
    I appreciated if anyone can help.
    Regards.
    Sha

  • Error while using Javamail...pls help me...

    when i am using javamail for sending mail , i am getting error like,
    C:\jdk1.3\bin\mail>java MailSend
    [email protected] [email protected]
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
    javax.mail.MessagingException:
    at javax.mail.Transport.send0(Transport.java:218)
    at javax.mail.Transport.send(Transport.java:80)
    at MailSend.Send(MailSend.java:56)
    at MailSend.main(MailSend.java:73)
    and i define properties like,
    mailProp.put("java", "java");
    where , "java" is my system name, and there is also mail server on my system. and my system is connected with proxy server..
    when i am trying
    mailProp.put("mail.smtp.host", "java");
    then i am getting same type of error...
    so, what is that ? pls help me to solve my error...

    Surely there's more information associated with that MessaginException than
    you've included here.
    Turn on session debugging and run your program again.
    http://java.sun.com/products/javamail/FAQ.html#debug

  • Error while sending mail when using Java Mail API

    Hi Experts,
    I am trying to execute a webdynpro application which uses the Java Mail API to send emails. The exception that I get on executing the application is :
    Sending failed;  nested exception is: javax.mail.SendFailedException: Invalid Addresses;  nested exception is: javax.mail.SendFailedException: 550 5.7.1 Unable to relay for [email protected]
    Can anybody please help me sort out the issue.
    Regards
    Abdullah

    Hi,
    Usually one get this error if the SMTP server is configured not to relay mails (a security measure) or the SMTP server need the mail to be sent from a trusted IP or with proper authentication. Some SMTP servers are configured to block junk mails.
    Pls check with your  mail server administrator.
    Regards

  • Getting error when sending SMTP mail using javamail api

    hi all
    i am new to javamail api...and using it first-time....i'v used the following code
    <%
    String mailHost="mail.mastsale.com";
    String mailText="Hello this is a test msg";
    String to="<a href="mailto:[email protected]">[email protected]</a>";
    String subject="jsp test mail";
    try
    String from="<a href="mailto:[email protected]">[email protected]</a>";
    String mailhost = "mail.mastsale.com";
    Properties props = System.getProperties();
    props.put("mail.smtp.host", mailhost);
    // Get a Session object
    Authenticator auth = new SMTPAuthenticator( "<a href="mailto:[email protected]">[email protected]</a>", "abcd" );
    Session session1 = Session.getInstance(props,auth);
    //Session.setDebug(true);
    //construct message
    Message msg = new MimeMessage(session1);
    msg.setFrom(new InternetAddress(from,"Your Name"));
    msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
    msg.setSubject(subject);
    msg.setText(mailText);
    //msg.setHeader("X-Mailer",mailer);
    msg.setSentDate(new Date());
    msg.saveChanges();
    //Send the message
    out.println("Sending mail to " + to);
    Transport.send(msg);
    catch (MessagingException me)
    out.println("Error in sending message for messaging exception:"+me);
    %>
    and
    SMTPAuthenticator.java
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class SMTPAuthenticator extends javax.mail.Authenticator {
    private String fUser;
    private String fPassword;
    public SMTPAuthenticator(String user, String password) {
    fUser = user;
    fPassword = password;
    public PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(fUser, fPassword);
    Now getting error as: Error in sending message for messaging exception:javax.mail.SendFailedException: Invalid Addresses; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 550-(host.hostonwin.com) [208.101.41.106] is currently not permitted to relay 550-through this server. Perhaps you have not logged into the pop/imap server 550-in the last 30 minutes or do not have SMTP Authentication turned on in your 550 email client.
    Can anyone help me?

    i got the following error while using the below code,
    -----------registerForm----------------
    DEBUG: setDebug: JavaMail version 1.3.2
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth true
    :::::::::::::::::::::::::::::::::<FONT SIZE=4 COLOR="blue"> <B>Error : </B><BR><HR> <FONT SIZE=3 COLOR="black">javax.mail.AuthenticationFailedException<BR><HR>
    -----------registerForm----------------
    public class SendMailBean {
    public String send(String p_from, String p_to, String p_cc, String p_bcc,
    String p_subject, String p_message, String p_smtpServer,String FilePath) {
    String l_result = "";
    // Name of the Host machine where the SMTP server is running
    String l_host = p_smtpServer;
    //for file attachment
    String filename = FilePath;
    // Gets the System properties
    Properties l_props = System.getProperties();
    // Puts the SMTP server name to properties object
    l_props.put("mail.smtp.host", l_host);
    l_props.put("mail.smtp.auth", "true");
    // Get the default Session using Properties Object
    Session l_session = Session.getDefaultInstance(l_props, null);
    l_session.setDebug(true); // Enable the debug mode
    try {
    MimeMessage l_msg = new MimeMessage(l_session); // Create a New message
    l_msg.setFrom(new InternetAddress(p_from)); // Set the From address
    // Setting the "To recipients" addresses
    l_msg.setRecipients(Message.RecipientType.TO,
    InternetAddress.parse(p_to, false));
    // Setting the "Cc recipients" addresses
    l_msg.setRecipients(Message.RecipientType.CC,
    InternetAddress.parse(p_cc, false));
    // Setting the "BCc recipients" addresses
    l_msg.setRecipients(Message.RecipientType.BCC,
    InternetAddress.parse(p_bcc, false));
    l_msg.setSubject(p_subject); // Sets the Subject
    // Create and fill the first message part
    MimeBodyPart l_mbp = new MimeBodyPart();
    //123
    ///////l_mbp.setText(p_message);
    l_mbp.setContent(p_message,"text/html");
    // Create the Multipart and its parts to it
    Multipart l_mp = new MimeMultipart();
         //l_mp.setContent(html,"text/html");
    l_mp.addBodyPart(l_mbp);
    // Add the Multipart to the message
    l_msg.setContent(l_mp,"text/html");
    // Set the Date: header
    l_msg.setSentDate(new Date());
    //added by cibijaybalan for file attachment
         // attach the file to the message
    //Multipart l_mp1 = new MimeMultipart();
         if(!filename.equals(""))
                   String fname = filename;
                   MimeBodyPart mbp2 = new MimeBodyPart();
                   FileDataSource fds = new FileDataSource(fname);
                   mbp2.setDataHandler(new DataHandler(fds));
                   mbp2.setFileName(fds.getName());
                   l_mp.addBodyPart(mbp2);
              // add the Multipart to the message
              l_msg.setContent(l_mp);
    //ends here
         l_msg.setSentDate(new java.util.Date());
    // Send the message
    Transport.send(l_msg);
    // If here, then message is successfully sent.
    // Display Success message
    l_result = l_result + "Mail was successfully sent to : "+p_to;
    //if CCed then, add html for displaying info
    //if (!p_cc.equals(""))
    //l_result = l_result +"<FONT color=green><B>CCed To </B></FONT>: "+p_cc+"<BR>";
    //if BCCed then, add html for displaying info
    //if (!p_bcc.equals(""))
    //l_result = l_result +"<FONT color=green><B>BCCed To </B></FONT>: "+p_bcc ;
    //l_result = l_result+"<BR><HR>";
    } catch (MessagingException mex) { // Trap the MessagingException Error
    // If here, then error in sending Mail. Display Error message.
    l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> "+
    "<FONT SIZE=3 COLOR=\"black\">"+mex.toString()+"<BR><HR>";
    } catch (Exception e) {
    // If here, then error in sending Mail. Display Error message.
    l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> "+
    "<FONT SIZE=3 COLOR=\"black\">"+e.toString()+"<BR><HR>";
    e.printStackTrace();
    }//end catch block
    //finally {
    System.out.println(":::::::::::::::::::::::::::::::::"+l_result);
    return l_result;
    } // end of method send
    } //end of bean
    plz help me

  • Error running SendMail when launch application from JNI

    Hello,
    I am getting the following exception when I try to send email using JavaMail. This error began happening when we upgraded to Java 1.6. It does not happen with earlier versions of Java.
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
         javax.mail.MessagingException: IOException while sending message;
    nested exception is:
         javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; boundary="----=_Part_0_2882193.1230049431911"
    I have browsed through the forums and read the many postings with a similar error. I have tried the variety of suggestions, but nothing seems to work. My understanding is the JAF is included in Java 1.6, so we should not need the activation.jar in our classpath anymore. Even so I have tried with and without the activation.jar in the classpath. I do not think it is a class loader issue because we do not build any of this into our application. It is all referenced in jar files on the classpath.
    The interesting thing is that I can launch the application with a normal JVM launch and it works just fine. The error only occurs when I launch the application from a C++ application using JNI. In both cases I am using the exact same classpath. The error occurs whether I include activation.jar in the classpath or not.
    I have tried to programmatically add the MIME types using the MailCommandMap class, but this had no effect.
    The most recent test I ran was to put the activation.jar and mail.jar files in my C:\Java\jre6\lib\endorsed directory. This actually cleared up the error. This is not a viable solution for us, but it leads me to believe the .mailcap file is not being loaded correctly for some reason. I just cannot figure out what the issue could be as it seems to be associated with JNI.
    Thank you for any help,
    Mary Kathryn

    Because JAF is now part of the JDK, the JAF classes are loaded by the system class loader
    instead of the application class loader. If the thread's context class loader is not set, JAF
    uses its class loader to load the mailcap files. Since JavaMail's mailcap file is in mail.jar,
    and mail.jar is still loaded by the application class loader, the system class loader can't
    find JavaMail's mailcap file.
    Normally, when starting the application using the "java" command, the thread's context
    class loader will be set to the application's class loader. This may not be happening
    automatically when starting the application with JNI.

  • Error Occurred while sending mail through gmail account

    Hello,
    I am writing 1 demo appln which will send a mail from my gmail account. It will show error like "javax.mail.MessagingException: 530 5.5.1 Authentication Required f77sm3109311pyh"
    Here is Code : -
    package demo;
    import java.util.Properties;
    import javax.mail.Address;
    import javax.mail.Authenticator;
    import javax.mail.Message;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    public class Demo {
         * @param args
         public static void main(String[] args) {
              try
              Properties properties=System.getProperties();
              properties.put("mail.smtp.host","smtp.gmail.com");
              properties.put("mail.smtp.auth","true");
              properties.put("mail.from","[email protected]");
              properties.put("mail.smtp.port","465");
              properties.put("mail.smtp.starttls.enable","true");          
              properties.put("mail.smtp.socketFactory.port", "465");
              properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
              properties.put("mail.smtp.socketFactory.fallback", "false");
              Authenticator auth = new PopupAuthenticator();
              Session session = Session.getDefaultInstance(properties,auth);                    
              session.setDebug(true);     
    //          Define message
              MimeMessage message = new MimeMessage(session);
              message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
              message.setSubject("Hello JavaMail");
              message.setText("Welcome to JavaMail");          
              message.saveChanges();
              Address address[] = message.getAllRecipients();
              Address a1 = address[0];
              System.out.println("Recipient : "+a1.toString());          
              Transport.send(message, message.getAllRecipients());
              catch(Exception e){e.printStackTrace();}
    and code for PopupAuthenticator :-
    package demo;
    import javax.mail.Authenticator;
    import javax.mail.PasswordAuthentication;
    import javax.swing.*;
    import java.util.StringTokenizer;
    public class PopupAuthenticator extends Authenticator
         public PopupAuthenticator()
              System.out.println("In Auth");
    public PasswordAuthentication getPasswordAuthentication()
    String username, password;
    String result = JOptionPane.showInputDialog("Enter 'username,password'");
    StringTokenizer st = new StringTokenizer(result, ",");
    username = st.nextToken();
    password = st.nextToken();
    return new PasswordAuthentication(username, password);
    But when i run this code i never get popup window asking for username/password and it throws follwing exception
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
         javax.mail.MessagingException: 530 5.5.1 Authentication Required f77sm3109311pyh
         at javax.mail.Transport.send0(Transport.java:204)
         at javax.mail.Transport.send(Transport.java:88)
         at demo.Demo.main(Demo.java:66)
    may i know wats wrong wid my code? I am confussed about when getPasswordAuthentication () method will call?
    please reply me at [email protected]
    thnx in advance ..
    -Sushrut

    Hi bshannon ,
    Thnx ..
    I have removed the popup code from my PopUpAuthanticer.java file
    But i got similar error ....
    Here is Debug message : -
    In Auth
    Recipient : [email protected]
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    DEBUG: SMTPTransport trying to connect to host "smtp.gmail.com", port 465
    DEBUG SMTP RCVD: 220 mx.google.com ESMTP y78sm4251719pyg
    DEBUG SMTP SENT: helo sushrutr
    DEBUG SMTP RCVD: 250 mx.google.com at your service
    DEBUG: SMTPTransport connected to host "smtp.gmail.com", port: 465
    DEBUG SMTP SENT: mail from: <[email protected]>
    DEBUG SMTP RCVD: 530 5.5.1 Authentication Required y78sm4251719pyg
    DEBUG SMTP SENT: quit
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
         javax.mail.MessagingException: 530 5.5.1 Authentication Required y78sm4251719pyg
         at javax.mail.Transport.send0(Transport.java:204)
         at javax.mail.Transport.send(Transport.java:88)
         at demo.Demo.main(Demo.java:53)
    can u please tell me when getPasswordAuthentication() will call ? and who is going to call this ...
    Thnx in advance ...

  • Send Email Java Error

    Dears,
    I have a database package to send an email to an employee, whole package working well except the send mail part, the error raised from java code i used says ( Can't send command to SMTP host No trusted certificate found).
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class SendMail {
       // Sender, Recipient, CCRecipient, and BccRecipient are
       // commaseparated lists of addresses.
       // Body can span multiple CR/LF-separated lines.
       // Attachments is a ///-separated list of file names.
       public static int Send(String SMTPServer,
                              String Sender,
                              String Recipient,
                              String CcRecipient,
                              String BccRecipient,
                              String Subject,
                              String Body,
                              String ErrorMessage[],
                              String Attachments) {
          // Error status
          int ErrorStatus = 0;
          // Create some properties and get the default Session
          Properties props = System.getProperties();
          //props.put("MyMailingServer", SMTPServer);
          props.put("mail.smtp.starttls.enable", "false");
         // mail.smtp.starttls.enable=false;
      props.put("mail.smtp.host", SMTPServer);
      props.put("mail.smtp.port", 25);
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.auth", "user");
      props.put("mail.smtp.auth", "password");
          Session session = Session.getDefaultInstance(props, null);
          try {
             // Create a message
             MimeMessage msg = new MimeMessage(session);
             // extracts the senders and adds them to the message
             // Sender is a comma-separated list of e-mail addresses as per RFC822
                InternetAddress[] TheAddresses = InternetAddress.parse(Sender);
                msg.addFrom(TheAddresses);
             // Extract the recipients and assign them to the message.
             // Recipient is a comma-separated list of e-mail addresses as per RFC822.
                InternetAddress[] TheAddresses = InternetAddress.parse(Recipient);
                msg.addRecipients(Message.RecipientType.TO,TheAddresses);
             // Extract the Cc-recipients and assign them to the message.
             // CcRecipient is a comma-separated list of e-mail addresses as per RFC822.
             if (null != CcRecipient) {
                InternetAddress[] TheAddresses = InternetAddress.parse(CcRecipient);
                msg.addRecipients(Message.RecipientType.CC,TheAddresses);
             // Extract the Bcc-recipients and assign them to the message.
             // BccRecipient is a comma-separated list of e-mail addresses as per RFC822.
             if (null != BccRecipient) {
                InternetAddress[] TheAddresses = InternetAddress.parse(BccRecipient);
                msg.addRecipients(Message.RecipientType.BCC,TheAddresses);
             // Subject field
             msg.setSubject(Subject);
             // Create the Multipart to be added the parts to
             Multipart mp = new MimeMultipart();
             // Create and fill the first message part
                MimeBodyPart mbp = new MimeBodyPart();
                mbp.setText(Body);
                // Attach the part to the multipart
                mp.addBodyPart(mbp);
             // Attach the files to the message
             if (null != Attachments) {
                int StartIndex = 0, PosIndex = 0;
                while (-1 != (PosIndex = Attachments.indexOf("///",StartIndex))) {
                   // Create and fill other message parts;
                   MimeBodyPart mbp = new MimeBodyPart();
                   FileDataSource fds =
                   new FileDataSource(Attachments.substring(StartIndex,PosIndex));
                   mbp.setDataHandler(new DataHandler(fds));
                   mbp.setFileName(fds.getName());
                   mp.addBodyPart(mbp);
                   PosIndex += 3;
                   StartIndex = PosIndex;
                // Last, or only, attachment file
                if (StartIndex < Attachments.length()) {
                   MimeBodyPart mbp = new MimeBodyPart();
                   FileDataSource fds = new FileDataSource(Attachments.substring(StartIndex));
                   mbp.setDataHandler(new DataHandler(fds));
                   mbp.setFileName(fds.getName());
                   mp.addBodyPart(mbp);
             // Add the Multipart to the message
             msg.setContent(mp);
             // set the Date: header
             msg.setSentDate(new Date());
             // Send the message
             Transport.send(msg);
          } catch (MessagingException MsgException) {
             ErrorMessage[0] = MsgException.toString();
             Exception TheException = null;
             if ((TheException = MsgException.getNextException()) != null)
               ErrorMessage[0] = ErrorMessage[0] + "\n" + TheException.toString();
               ErrorStatus = 1;
          return ErrorStatus;
       } // End Send Class
    } // End of public class SendMail

    i changed my smtp server and now i am getting the following error...please help
    C:\trainee>java Emailer
    Cannot send email. javax.mail.SendFailedException: Invalid Addresses;
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 504 <nb123@tcs05>: Sende
    r address rejected: need fully-qualified address
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 504 <nb123@tcs05>: Sende
    r address rejected: need fully-qualified address
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 504 <nb123@tcs05>: Sende
    r address rejected: need fully-qualified address

  • OEM Email Notification:: "Relay access denied " Error

    Hello all,
    The IP address of the OEM grid server was changed very recently.
    Though everythin works perfectly after that, 'am not getting any mail notifications that i used to get before.
    The Outgoing Mail (SMTP) Server ip is the same as it was previously
    In OEM, Setup => Notification Methods =>Test Mail Servers ::gives the below errors.
    <smtp ip addr>: Test failed with message: "Sending failed; nested exception is: javax.mail.SendFailedException: Invalid Addresses; nested exception is: javax.mail.SendFailedException: 554 <[email protected]>: Relay access denied "
    Is there anywhere i need to make any change??
    TIA,
    J J

    Well, This was coz dat the "relaying" for the new ip address was not enabled in the mail server.
    J J

  • Java mail api error- Please Help

    Hi, i have set up an smtp server on my local machine. i have given the smtp host address as 127.0.0.1
    I am getting the following error though. please help me out with the problem
    C:\trainee>java Emailer
    javax.mail.SendFailedException: Invalid Addresses;
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1196)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584)
    at javax.mail.Transport.send0(Transport.java:169)
    at javax.mail.Transport.send(Transport.java:98)
    at Emailer.sendEmail(Emailer.java:151)
    at Emailer.main(Emailer.java:194)
    Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1047)
    ... 5 more
    Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    ... 6 more
    Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    ... 6 more

    It's a configuration error in your smtp server.
    See the JavaMail FAQ for more information.

  • Javax.mail.SendFailedException

    HI all,
    I have an application which reads .csv file, picks up email ids and sends e-mail to mentioned 'to' address.
    There are 199 diffreent email ids. I could send upto 90 emails.
    But, after that, i got following error !
    error message:
    javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: Could not connect to SMTP host: mail.**********.com, port: 25
    I don't know the reason for it. Can any one please guide me in this regard?
    Thanks in advance !
    Regards
    Ashvini

    Try to give all the address in TO field with comma seperation and check it out.
    Regards
    Balu

  • Error in Send Email Option

    Hi,
    I have task assignment adapeter and map to my approval process.
    I have written the following method in that adapter to send e-mail to a list of ppl.
    sendEmailNotifications( tcDataProvider dataProvider, String emailDefName, Vector pvToAddress) {
    emailUtilIntf = new tcEmailNotificationUtil(dataProvider);
    emailUtilIntf.constructEmail(emailDefName);
    emailUtilIntf.sendEmail(pvToAddress);
    I Pass the correct parameters to this but it give me a following error.
    ERROR [XELLERATE.REQUESTS] Class/Method: tcEmailNotificationUtil/sendEmail(Vector pvToAddress) encounter some problems: Sending failed;
    nested exception is:
    class javax.mail.MessagingException: Unknown SMTP host: XL.MailServer;
    nested exception is:
    java.net.UnknownHostException: XL.MailServer
    javax.mail.SendFailedException: Sending failed;
    If I try to send mails through Notification tab by using same e-mail definition. It works fine....
    Can some one help me regarding this Issue ?
    /BR
    Thirlk

    Thanx Rajiv...
    It's working fine:)
    When I send the email to one user at a time, it works ( As U r Code ). Seems to be a problem in overload method which take "Vector".
    But now I have a another probelm,
    The code will take the correct email definition and send it but in that email, the request id and other valus I set in the email definition doesn't have any valus.
    Ex : Approval Request Assigned ( Request ID : <Request Information.Request ID> ) - This is the subject in my email definition but if i send mails through Notification tab, the " <Request Information.Request ID> " will be replaced with correct request Id but in this case it won't happen and just display it as *<Request Information.Request ID>*
    Can some one help me over this ?

  • SendFailedException: 421 Refused. Your reverse DNS

    I'm sending e-mail confirmations from my website. I'm occasionally getting this SendFailedException:
    class javax.mail.SendFailedException: 421 Refused. Your reverse DNS entry does not resolve. See: http://my.policy.explanation.url/
    I can load the link to get more information. I'm successfully sending e-mail most of the time, but this error appears a few times a day.
    I've poked around on the web to try to get more information and haven't found much.
    Any ideas what is going on or how to get more information?

    Looks like your mail server is having DNS problems.
    If you run your own DNS server, check that, otherwise
    check with your ISP. Or, if your web site is hosted
    by someone else, check with them. Either way, it's
    not a JavaMail problem.

Maybe you are looking for