How to send Secured Mail using Java Mail?

I want to send mails with "Send Secure" option using Java Mail. Now mails are being sent using Java Mail connecting to smtp host.
Appreciating your help.
Thanks.

There are third party libraries to help with this. Bouncy Castle is very popular.
See the [JavaMail Third Party Products|http://java.sun.com/products/javamail/Third_Party.html] page.

Similar Messages

  • How to send secure email using JavaMail

    Hi, anyone out there know how to send secure email using Java Mail? Greately appreciated.

    For starters, if you have not already done so, read about it in the JavaMail design specifications.
    Search for Message Security in the said document.

  • How to send HTML Format Mail using Java Mail in oracle 9i Forms

    Dear All
    could you please tell me how to send HTML Format Mail using Java Mail in oracle 9i Forms and how to implement the java mail ?
    if it is possible, could you please send me the sample code? please very urgent
    Thanks
    P.Sivaraman

    Hello,
    <p>Here is a Form sample.</p>
    Francois

  • How to Read An Attachment Using Java Mail

    Hi
    I Am Able To Read The Mail Using Java Mail ,but Unable To Read The Attachment Which Comes Along With The Mail.
    Please Help Me , In Reading The Attachment.

    Hi
    I Am Able To Read The Mail Using Java Mail ,but
    t Unable To Read The Attachment Which Comes Along
    With The Mail.
    Please Help Me , In Reading The Attachment.Do you mean:
    - I only recieve .txt or .doc attachments and I want to see the contents? Or could you get a .jpg as well?
    or
    - Do you need to seperate the attachment from the e-mail and then view it?

  • Sending HTML E Mail using Java Mail

    Can anybody please tell me how to send HTML email using JavaMail. I know I need the DataContentHandler for text/html mime type but where can I find one? If anybody has better suggestions you are welcome.

    Folks,
    I've used what you have suggested. Though it compiled, I kept getting this java error
    --Exception in MailServer.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 text/html
    at javax.mail.Transport.send0(Transport.java:204)
    at javax.mail.Transport.send(Transport.java:73)
    at MailTest.send(MailTest.java:419)
    at MailTest.sendThruDefaultServer(MailTest.java:319)
    at MailTest.main(MailTest.java:476)
    [sendEmail() - Exception  :javax.activation.UnsupportedDataTypeException
    HELP!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to send html messages using unix mail ?

    Hi,
    I'm wondering if it's possible to send html formated mail using Unix mail command ?
    Regards,
    Didier.

    It works fine for me right out of the box; I've done zero to configure anything. In my case, I presume the HTML is encoded in a file. Then I invoke a script which adds the following mail headers before the HTML, then calls sendmail:
    <pre class=command>MIME-Version: 1.0
    Content-type: text/html; charset=ISO-8859-1
    To: $address
    From: $MY_EMAIL
    Subject: File: $subject
    </pre>
    In the header, variables $address, $MY_EMAIL, and $subject are filled in by the shell script.
    HTH

  • How to send sms,Email using java

    how to send sms,Email using java

    Hi,
    There are many sms gateways that have their own api to send sms. You can use them for sms. (They will charge you for the sms!!!)
    Moderator edit: Link removed
    Thanks
    Edited by: PhHein on 20.10.2010 16:11

  • How to send e-mail using java mail api

    Hi can anyone tell me how to send mail using the javamail api, in short if possible an example code.

    Theres already lots of this code in the forums, use the search bar to the left.
    Also, there is a dedicated javaMail forum which you will find useful (you are currently in a JSP forum)
    http://forum.java.sun.com/forum.jspa?forumID=43

  • How to send multiple Recipients using the mail.jar and activation.jar

    hi!
    could somebody help me. how do i send multiple Recipient using mail.jar. when i would input 2email address in to Recipient
    (example: [email protected], [email protected])
    i get a DEBUG: setDebug: JavaMail version 1.3.2
    but if i send a single email it just works properly.
    heres my code
    import java.io.*;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.event.*;
    import javax.mail.internet.*;
    public class SendMail
              public SendMail(String to, String from, String subject, String body)
              //public SendMail(String to)
                   String message_recip = to;
                   String message_subject = subject;
                   String message_cc = "";
                   String message_body = body;
                   //The JavaMail session object
                   Session session;
                   //The JavaMail message object
                   Message mesg;
                   // Pass info to the mail server as a Properties, since JavaMail (wisely) allows room for LOTS of properties...
                   Properties props = new Properties( );
                   // LAN must define the local SMTP server as "mailhost" to be able to send mail...
                   //props.put("mail.smtp.host","true");
                   props.put("mail.smtp.host", "mailhost");
                   // Create the Session object
                   session = Session.getDefaultInstance(props, null);
                   session.setDebug(true);
                   try
                        // create a message
                        mesg = new MimeMessage(session);
                        // From Address - this should come from a Properties...
                        mesg.setFrom(new InternetAddress(from));
                        // TO Address
                        InternetAddress toAddress = new InternetAddress(message_recip);
                        mesg.addRecipient(Message.RecipientType.TO, toAddress);
                        // CC Address
                        InternetAddress ccAddress = new InternetAddress(message_cc);
                        mesg.addRecipient(Message.RecipientType.CC, ccAddress);
                        // The Subject
                        mesg.setSubject(message_subject);
                        // Now the message body.
                        mesg.setText(message_body);
                        // XXX I18N: use setText(msgText.getText( ), charset)
                        // Finally, send the message!
                        Transport.send(mesg);
                   }//end of try
                   catch (MessagingException ex)
                        while ((ex = (MessagingException)ex.getNextException( )) != null)
                             ex.printStackTrace( );
                        }//end of while
              }//end of catch
         }//end of SendMail
    public static void main(String[] args)
              //String t = "[email protected], [email protected]"; - this I think causes error
    String t = "[email protected]";
              String f = "[email protected]";
              String s = "Hello World";
              String b = "the quick brown fox jumps over the lazy dog";
              SendMail sm = new SendMail(t,f,s,b);     
         }//end of main
    }//end of class
    could someone please help me im stuck-up with this. thanx!

    i need it ASAP
    i am a beginner in java and jsp
    Need to knw how can I parse the addresss field
    Below
    is the code
    <code>
    package
    public class EMailBean {
    private String smtp,username,password,from,bcc,subject,body,attachments,cc;
         /*setter*/
         public void setSmtp(String str){this.smtp=str;}
         public void setUsername(String str){this.username=str;}
         public void setPassword(String str){this.password=str;}
         public void setFrom(String str){this.from=str;}
         public void setTo(String str){this.to=str;}
         public void setCc(String str){this.cc=str;}
         public void setBcc(String str){this.bcc=str;}
         public void setSubject(String str){this.subject=str;}
         public void setBody(String str){this.body=str;}
         public void setAttachments(String str){this.attachments=str;}
                                  /*getter*/
         public String getSmtp( ){return this.smtp;}
         public String getUsername( ){return this.username;}
         public String getPassword( ){return this.password;}
         public String getFrom( ){return this.from;}
         public String getTo( ){return this.to;}
         public String getCc( ){return this.cc;}     
         public String getBcc( ){return this.bcc;}
         public String getSubject( ){return this.subject;}
         public String getBody( ){return this.body;}
    public String getAttachments( ){return this.attachments;}
    </code>
    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(true);
    try {
    MimeMessage msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(mail.getFrom()));
                                  msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
                                  msg.addRecipient(Message.RecipientType.TO,new InternetAddress(mail.getTo()));
                             msg.addRecipient(Message.RecipientType.CC, new InternetAddress(mail.getCc()));
                                  msg.addRecipient(Message.RecipientType.CC, new InternetAddress("[email protected]"));
    msg.setSubject(mail.getSubject());
    // Create the message part
    BodyPart messageBodyPart = new MimeBodyPart();
    // Fill the message
    messageBodyPart.setText(mail.getBody());
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    // Part two is attachment
    messageBodyPart = new MimeBodyPart();
    DataSource source = new FileDataSource(mail.getAttachments());
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName(source.getName());
    multipart.addBodyPart(messageBodyPart);
    msg.setContent(multipart);
    msg.setSentDate(new Date());
    Transport t = session.getTransport("smtp");
    try {
    t.connect(mail.getUsername(), mail.getPassword());
    t.sendMessage(msg, msg.getAllRecipients());
    } finally {
    t.close();
    result = result + "<FONT SIZE='4' COLOR='blue'><B>Success!</B>"+"<FONT SIZE='4' COLOR='black'> "+"<HR><FONT color='green'><B>Mail was successfully sent to </B></FONT>: "+mail.getTo()+"<BR>";
    if (!("".equals(mail.getCc())))
    result = result +"<FONT color='green'><B>CCed To </B></FONT>: "+mail.getCc()+"<BR>";
    if (!("".equals(mail.getBcc())))
    result = result +"<FONT color='green'><B>BCCed To </B></FONT>: "+mail.getBcc() ;
    result = result+"<BR><HR>";
    } catch (MessagingException mex) {
    result = result + "<FONT SIZE='4' COLOR='blue'> <B>Error : </B><BR><HR> "+"<FONT SIZE='3' COLOR='black'>"+mex.toString()+"<BR><HR>";
    } catch (Exception e) {
    result = result + "<FONT SIZE='4' COLOR='blue'> <B>Error : </B><BR><HR> "+"<FONT SIZE='3' COLOR='black'>"+e.toString()+"<BR><HR>";
    e.printStackTrace();
    finally {
    return result;
    }

  • Problem in sending mail using java mail api

    This is the pogram I am using as of now to send a mail to yahoo id.
    import javax.mail.*;
    import javax.mail.internet.*;
    public class SendingMail2
    public SendingMail2()
    try
    String from = "ravikiran_sunrays";
    String to = "[email protected]";
    String subject = "the subject u wanna send ";
    String cc="[email protected]";
    String bcc="[email protected]";
    String text="the matter that u wanna send ";
    java.util.Properties prop = System.getProperties();
    prop.put("mail.smtp.host","mail.yahoo.com");
    //prop.put("http.proxyHost",System.getProperty("http.proxyHost"));
    //prop.put("http.proxyPort","8080");
    //prop.put("http.proxyPort",System.getProperty("http.proxyPort"));
    //prop.put("http.proxyHost","172.19.48.201");
    //System.getProperties().setProperty("http.proxyPort","8080");
    //System.getProperties().setProperty("http.proxyHost","172.19.48.201");
    Session ses = Session.getInstance(prop,null);
    MimeMessage message = new MimeMessage(ses);
    try
    Address fromAddress = new InternetAddress(from);
    message.setFrom(fromAddress);
    message.setSubject(subject);
    Address[] toAddress = InternetAddress.parse(to);
    Address[] cc_address=InternetAddress.parse(cc);
    Address[] bcc_address=InternetAddress.parse(bcc);
    message.setRecipients(Message.RecipientType.TO,toAddress);
    message.setRecipients(Message.RecipientType.CC,cc_address);
    message.setRecipients(Message.RecipientType.BCC,bcc_address);
    message.setSentDate(new java.util.Date());
    message.setText(text);
    Transport.send(message);
    System.out.println("Mail Successfully Sent");
    catch(Exception e)
    System.out.println("Problem " + e);
    catch(Exception e)
    System.out.println("Problem " + e);
    public static void main(String[] args)
    SendingMail2 sendingMail2 = new SendingMail2();
    This is the exception I am getting when I try 2 execute that program.
    avax.mail.SendFailedException: Sending failed;
    nested exception is:
         javax.mail.MessagingException: Unknown SMTP host: mail.yahoo.com;
    nested exception is:
         java.net.UnknownHostException: mail.yahoo.com

    listen buddy
    this is a class i made it is easy to understand it sends mails and check inbox just adduser from telnet with remote manager in james create the three accounts i am using and then use this class and its methods
    also the next class that contains the mails test my class and what i am saying
    import java.io.*;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class MailClient
    extends Authenticator
    public static final int SHOW_MESSAGES = 1;
    public static final int CLEAR_MESSAGES = 2;
    public static final int SHOW_AND_CLEAR =
    SHOW_MESSAGES + CLEAR_MESSAGES;
    protected String from;
    protected Session session;
    protected PasswordAuthentication authentication;
    public MailClient(String user, String host)
    this(user, host, false);
    public MailClient(String user, String host, boolean debug)
    from = user + '@' + host;
    authentication = new PasswordAuthentication(user, user);
    Properties props = new Properties();
    props.put("mail.user", user);
    props.put("mail.host", host);
    props.put("mail.debug", debug ? "true" : "false");
    props.put("mail.store.protocol", "pop3");
    props.put("mail.transport.protocol", "smtp");
    session = Session.getInstance(props, this);
    public PasswordAuthentication getPasswordAuthentication()
    return authentication;
    public void sendMessage(
    String to, String subject, String content)
    throws MessagingException
    System.out.println("SENDING message from " + from + " to " + to);
    System.out.println();
    MimeMessage msg = new MimeMessage(session);
    msg.addRecipients(Message.RecipientType.TO, to);
    msg.setSubject(subject);
    msg.setText(content);
    Transport.send(msg);
    public void checkInbox(int mode)
    throws MessagingException, IOException
    if (mode == 0) return;
    boolean show = (mode & SHOW_MESSAGES) > 0;
    boolean clear = (mode & CLEAR_MESSAGES) > 0;
    String action =
    (show ? "Show" : "") +
    (show && clear ? " and " : "") +
    (clear ? "Clear" : "");
    System.out.println(action + " INBOX for " + from);
    Store store = session.getStore();
    store.connect();
    Folder root = store.getDefaultFolder();
    Folder inbox = root.getFolder("inbox");
    inbox.open(Folder.READ_WRITE);
    Message[] msgs = inbox.getMessages();
    if (msgs.length == 0 && show)
    System.out.println("No messages in inbox");
    for (int i = 0; i < msgs.length; i++)
    MimeMessage msg = (MimeMessage)msgs;
    if (show)
    System.out.println(" From: " + msg.getFrom()[0]);
    System.out.println(" Subject: " + msg.getSubject());
    System.out.println(" Content: " + msg.getContent());
    if (clear)
    msg.setFlag(Flags.Flag.DELETED, true);
    inbox.close(true);
    store.close();
    System.out.println();
    ====================================
    testing this class
    =======================================
    public class JamesConfigTest
    public static void main(String[] args)
    throws Exception
    // CREATE CLIENT INSTANCES
    MailClient redClient = new MailClient("red", "localhost");
    MailClient greenClient = new MailClient("green", "localhost");
    MailClient blueClient = new MailClient("blue", "localhost");
    // CLEAR EVERYBODY'S INBOX
    redClient.checkInbox(MailClient.CLEAR_MESSAGES);
    greenClient.checkInbox(MailClient.CLEAR_MESSAGES);
    blueClient.checkInbox(MailClient.CLEAR_MESSAGES);
    Thread.sleep(500); // Let the server catch up
    // SEND A COUPLE OF MESSAGES TO BLUE (FROM RED AND GREEN)
    redClient.sendMessage(
    "blue@localhost",
    "Testing blue from red",
    "This is a test message");
    greenClient.sendMessage(
    "blue@localhost",
    "Testing blue from green",
    "This is a test message");
    Thread.sleep(500); // Let the server catch up
    // LIST MESSAGES FOR BLUE (EXPECT MESSAGES FROM RED AND GREEN)
    blueClient.checkInbox(MailClient.SHOW_AND_CLEAR);
    =======================================================
    it suppose to print this
    Clear INBOX for red@localhost
    Clear INBOX for green@localhost
    Clear INBOX for blue@localhost
    SENDING message from red@localhost to blue@localhost
    SENDING message from green@localhost to blue@localhost
    Show and Clear INBOX for blue@localhost
    From: green@localhost
    Subject: Testing blue from green
    Content: This is a test message
    From: red@localhost
    Subject: Testing blue from red
    Content: This is a test message
    thanks a lot
    but i need ur help plzzzzzzzzzzzz
    i can create account from telnet
    but how i can create a new account from java .. a jsp page that i made to create a new account on the server
    plzzzzzzzz help me
    bye

  • Not able to sending the Mail using java mail utility

    Hi, I am new to java mail utility and written first time for sending mail. If any body an help me out in resolving the problem I would be thankful to him/her........below is the code which I m trying......
    package test;
    import javax.servlet.http.HttpServlet;
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.AddressException;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    /*import javax.mail.Address;
    import javax.mail.Authenticator;
    import javax.mail.MessagingException;
    import javax.mail.NoSuchProviderException;
    import javax.mail.PasswordAuthentication;
    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;*/
    * @author chauhasd
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    public class SendMailServlet extends HttpServlet{
         public SendMailServlet(){
         public void sendMail(){
              java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
              Properties props=new Properties();
              props.put("mail.transport.protocol", "smtp");
              props.put("mail.smtp.host","pcsttc.patni.com");
              props.put("mail.smtp.port","25");
              props.put("mail.smtp.auth","true");
              props.put("mail.smtp.starttls.enable","true");
              Session session=Session.getDefaultInstance(props,new MyAuthenticator());
              session.setDebug(true);
              MimeMessage message=new MimeMessage(session);
              try{
                   message.setContent("Hello....","text/plain");
                   message.setSubject("Testing Mail");
                   Address strTo = new InternetAddress("[email protected]");
                   Address strFrom = new InternetAddress("[email protected]");
                   Address strReplyTO = new InternetAddress("[email protected]");
                   message.setFrom(strFrom);
                   message.setReplyTo(new Address[]{strReplyTO});
                   message.setRecipient(Message.RecipientType.TO,strTo);
                   Transport.send(message);
              }catch (AddressException e)
    //               TODO Auto-generated catch block
                   e.printStackTrace();
              }catch (NoSuchProviderException e){
    //               TODO Auto-generated catch block
                   e.printStackTrace();
              }catch (MessagingException e){
    //               TODO Auto-generated catch block
                   e.printStackTrace();
         protected PasswordAuthentication getPasswordAuthentication()
              return new PasswordAuthentication("[email protected]", "sid35789");
         public static void main(String [] args){
              new SendMailServlet().sendMail();
    ERROR :
    DEBUG: setDebug: JavaMail version 1.3.1
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth true
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
         class javax.mail.AuthenticationFailedException
         at javax.mail.Transport.send0(Transport.java:218)
         at javax.mail.Transport.send(Transport.java:80)
         at test.SendMailServlet.sendMail(SendMailServlet.java:59)
         at test.SendMailServlet.main(SendMailServlet.java:81)

    Sangyesh wrote:
    In my application,we already implemented it so we cant go for javamail.That does not make sense. Your 'implementation' does not work so you have not yet fully 'implemented' it. Using Javamail takes about 4 lines of code to do what you have done so far and it will work.
    Please suggest me regarding this,so that I can go ahead and resolve it.Use the Javamail API.

  • Problems while sending mail using java mail..help...

    Hello all,
    I am new to Java Mail...
    Below is my first program...
    Can anybody tell what's wrong in it..??
    Thanks in advance....
    ------------------------------------------------------start--------------------
    package test;
    import java.util.Properties;
    import javax.mail.Address;
    import javax.mail.Authenticator;
    import javax.mail.MessagingException;
    import javax.mail.NoSuchProviderException;
    import javax.mail.PasswordAuthentication;
    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 Send
         public Send()
         public void send()
              java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
              Properties props=new Properties();
              props.put("mail.transport.protocol", "smtp");
              props.put("mail.smtp.host","smtp.gmail.com");
              props.put("mail.smtp.port","25");
              props.put("mail.smtp.auth","true");
              Session session=Session.getDefaultInstance(props,new MyAuthenticator());
              session.setDebug(true);
              MimeMessage message=new MimeMessage(session);
              try
                   message.setContent("Hello ...","text/plain");
                   message.setSubject("Test mail...plz don't ignore..");
                   Address to=new InternetAddress("[email protected]");
                   Address from=new InternetAddress("[email protected]");
                   Address replyTo=new InternetAddress("[email protected]");
                   message.setFrom(from);
                   message.setReplyTo(new Address[]{replyTo});
                   message.setRecipient(RecipientType.TO,to);               
                   Transport.send(message);
              } catch (AddressException e)
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (NoSuchProviderException e)
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (MessagingException e)
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         public static void main(String[] args)
              new Send().send();          
         class MyAuthenticator extends Authenticator
              MyAuthenticator()
                   super();
              protected PasswordAuthentication getPasswordAuthentication()
                   return new PasswordAuthentication("[email protected]", "*******");
    --------------------------------------------end--------------
    here is the output.....
    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
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL false
    220 mx.gmail.com ESMTP 16sm2443823wrl
    DEBUG SMTP: connected to host "smtp.gmail.com", port: 25
    EHLO jijo
    250-mx.gmail.com at your service
    250-SIZE 20971520
    250-8BITMIME
    250-STARTTLS
    250 ENHANCEDSTATUSCODES
    DEBUG SMTP: Found extension "SIZE", arg "20971520"
    DEBUG SMTP: Found extension "8BITMIME", arg ""
    DEBUG SMTP: Found extension "STARTTLS", arg ""
    DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
    DEBUG SMTP: use8bit false
    MAIL FROM:<[email protected]>
    530 5.7.0 Must issue a STARTTLS command first
    com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
         at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1275)
         at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:895)
         at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:524)
         at javax.mail.Transport.send0(Transport.java:151)
         at javax.mail.Transport.send(Transport.java:80)
         at test.Send.send(Send.java:50)
         at test.Send.main(Send.java:68)
    QUIT
    com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
         at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1275)
         at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:895)
         at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:524)
         at javax.mail.Transport.send0(Transport.java:151)
         at javax.mail.Transport.send(Transport.java:80)
         at test.Send.send(Send.java:50)
         at test.Send.main(Send.java:68)
    Can any body help me..??
    Thanks and Regards
    Jijo vincent

    Hi All,
    I am new to javax.mail.
    I have attached my code and also error here...
    can anyone help to resolve the error?
    Code:
    public class MailExample {
         public static void main(String args[]) {
              try {
              String host = "localhost"; //args[0];
              String from = "[email protected]"; //args[1];
    //          String to = "[email protected]";//args[2];
              String to = "[email protected]";//args[2];
              java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
              // Get system properties
              Properties props = System.getProperties();
              // Setup mail server
              props.put("mail.smtp.host", host);
              props.put("mail.smtp.starttls.enable","true");
              //props.put("mail.smtp.auth","true");
              // Get session
              Session session = Session.getDefaultInstance(props, null);
              session.setDebug(true);
              // Define message
              MimeMessage message = new MimeMessage(session);
              // Set the from address
              message.setFrom(new InternetAddress(from));
              // Set the to address
              message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
              // Set the subject
              message.setSubject("Hello JavaMail");
              // Set the content
              message.setText("Welcome to JavaMail");
              // Send message
              Transport.send(message);
              catch(AddressException ae){
                   ae.printStackTrace();
              }catch (MessagingException e)
    //               TODO Auto-generated catch block
                   e.printStackTrace();
    Error:
    DEBUG: setDebug: JavaMail version 1.3.3ea
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth false
    DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false
    220 localhost
    DEBUG SMTP: connected to host "localhost", port: 25
    EHLO HDCHCTDAM33726
    250-localhost
    250 HELP
    DEBUG SMTP: Found extension "HELP", arg ""
    DEBUG SMTP: use8bit false
    MAIL FROM:<[email protected]>
    250 [email protected] Address Okay
    RCPT TO:<[email protected]>
    250 [email protected] Address Okay
    DEBUG SMTP: Verified Addresses
    DEBUG SMTP: [email protected]
    DATA
    354 Start mail input; end with <CRLF>.<CRLF>
    Message-ID: <10736847.01125315340863.JavaMail.sangeetham@HDCHCTDAM33726>
    From: [email protected]
    To: [email protected]
    Subject: Hello JavaMail
    MIME-Version: 1.0
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Welcome to JavaMail
    com.sun.mail.smtp.SMTPSendFailedException: 550 Invalid recipient: [email protected]
         at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)
         at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1160)
         at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:538)
         at javax.mail.Transport.send0(Transport.java:151)
         at javax.mail.Transport.send(Transport.java:80)
         at org.worldbank.webmfr.util.MailExample.main(MailExample.java:55)550 Invalid recipient: [email protected]
    com.sun.mail.smtp.SMTPSendFailedException: 550 Invalid recipient: [email protected]
         at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)
         at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1160)
         at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:538)
         at javax.mail.Transport.send0(Transport.java:151)
         at javax.mail.Transport.send(Transport.java:80)
         at org.worldbank.webmfr.util.MailExample.main(MailExample.java:55)
    QUIT

  • How to forward and reply using java mail?

    Im new to java mail...
    Can anybody give me a detailed examples for
    1. forwarding a mail
    2. Replying to mail
    from javamail?
    thanks in advance
    sandhya

    Detailed? Not necessary. You have to create a new message and send it, that's all. Note that the Message has a reply() method that helps you to do that.

  • Problems in Sending mails using java mail

    hi all,
    heres my piece of code-
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import javax.mail.Authenticator;
    import javax.mail.PasswordAuthentication;
    public class SendEmail
         public static void main(String[] args)
    System.out.println(args.length);
              if (args.length != 6)
                   System.out.println("usage: sendmessage <to> <from> <smtphost> <true|false> <subject> <text>");
                   System.exit(1);System.out.println("jj"+args.length);
         SendEmail m=new SendEmail();
         m.SendMessage(args[0],args[1], args[2], args[3], args[4], args[5]);
    public static String SendMessage(String emailto, String emailfrom, String smtphost, String emailmultipart, String msgSubject, String msgText)
         boolean debug = false; // change to get more information
    String msgText2 = "multipart message";
    boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue();
    // set the host
    Properties props = new Properties();
    props.put("mail.smtp.host",smtphost);
         props.put("mail.smtp.starttls.enable","true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.sendpartial", "true");
    Authenticator loAuthenticator = new SMTPAuthenticator();
    System.out.println("f");
    // create some properties and get the default Session
    Session session = Session.getDefaultInstance(props, loAuthenticator );
    session.setDebug(debug);
    System.out.println("ff");
    //System.out.println( loAuthenticator);
    try
    // create a message
    Message msg = new MimeMessage(session);
    // set the from
    InternetAddress from = new InternetAddress(emailfrom);
    msg.setFrom(from);
    InternetAddress[] address =
    new InternetAddress(emailto)
    //InternetAddress ad=new InternetAddress(session);
    //System.out.println(ad.getLocalAddress());
    msg.setRecipients(Message.RecipientType.TO, address);
    msg.setSubject(msgSubject);
    if(!sendmultipart)
    // send a plain text message
    msg.setContent(msgText, "text/plain");
    else
    // send a multipart message// create and fill the first message part
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setContent(msgText, "text/plain");
    // create and fill the second message part
    MimeBodyPart mbp2 = new MimeBodyPart();
    mbp2.setContent(msgText2, "text/plain");
    // create the Multipart and its parts to it
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
    mp.addBodyPart(mbp2);
    // add the Multipart to the message
    msg.setContent(mp);
    Transport transport = session.getTransport("smtp");
         transport.connect(smtphost,"[email protected]","xyz");
    msg.saveChanges();
              //transport.sendMessage(msg,msg.getAllRecipients());
    transport.sendMessage(msg,msg.getAllRecipients());
    transport.close();     
    catch(MessagingException mex)
    mex.printStackTrace();
    return "Email sent to " + emailto;
    class SMTPAuthenticator extends Authenticator
    public PasswordAuthentication getPasswordAuthentication()
    String username = "[email protected]";
    String password = "xyz";
    return new PasswordAuthentication(username, password);
    i get the following errors-
    SmtpSendFailedException:550 Invalid Recipient
    Sometimes the mail gets send but sometimes it doesnt (while sending it to yahoo)..
    i guess there is some firewall problem..
    can somebody help me please.
    thanks

    Hello. I don't know if this will help you much but just reading the posts there might be something wrong with the information that is being sent to your SMTP host. You might make sure that the string that you are sending doesn't have extra characters attached to it or that a timeout is not occuring during the transfer of your username/password information. Sometimes the '@' gets translated into something else.
    A 550 error usually indicates that the mail server didn't recived a valid user on the system, this came into play I believe when people start abusing SMTP to SPAM a server using everything under the sun...so filters were put in place i.e. If you are not a Qualified Domain Name registered mailserver and someone has a filter in place your message will go kersplat because forwarding is no longer being allowed. Yopu might try a diffrent tactic.
    1. you might trim your strings.
    2. build strings in a connect method so that its a bit less amateur code.
    public void connect() {
            // Display connect dialog.
            ConnectDialog dialog = new ConnectDialog(this);
            dialog.show();
            // Build connection URL from connect dialog settings.
            StringBuffer connectionUrl = new StringBuffer();
            connectionUrl.append(dialog.getType() + "://");
            connectionUrl.append(dialog.getUsername() + ":");
            connectionUrl.append(dialog.getPassword() + "@");
            connectionUrl.append(dialog.getServer() + "/");3. Make absolutely certain that the SMTP server you are sending from is registered and qualified in your code. Meaning you can't use a bogus MTA(mail trasport agent) or you get bounced.
       private void sendMessage(int type, Message message) {
            // Display message dialog to get message values.
            MessageDialog dialog;
            try {
                dialog = new MessageDialog(this, type, message);
                if (!dialog.display()) {
                    // Return if dialog was cancelled.
                    return;
            } catch (Exception e) {
                showError("Unable to send message.", false);
                return;
            try {
                // Create a new message with values from dialog.
                Message newMessage = new MimeMessage(session);
                newMessage.setFrom(new InternetAddress(dialog.getFrom()));
                newMessage.setRecipient(Message.RecipientType.TO,
                        new InternetAddress(dialog.getTo()));
                newMessage.setSubject(dialog.getSubject());
                newMessage.setSentDate(new Date());
                newMessage.setText(dialog.getContent());
                // Send new message.
                Transport.send(newMessage);
            } catch (Exception e) {
                showError("Unable to send message.", false);
        }Lastly, if you are writing a SPAM client, you should go to your dos prompt and type format c: (j/k)
    now the disclaimer. The code published is not mine it was a piece of an example that I got from a brillient book by Herbert Schildt and James Holmes who I would love to be able to chat with since the work they do is absolutely perfect. You might check it out from your Local Library the ISBN is 0-07-222971-3 they have a whole section just on JavaMail.
    Well hope that gets you started in the right direction, I would read the ISO standards published for SMTP, you might get a better grip on the error codes that are bound to come up.

  • What are the prerequisits i need to send a mail using java mail

    i have a class file using javamail.
    I want to validate the email id's and send to particular address.
    will u please tell me the process and prerequisits to send the mail(like SMTP server,username ,password..)
    Please what actually username , password is ment in an authenticated javamail program.
    is it user account on SMTP server / email id
    Thanks.
    Prasantha Reddy C

    Hi,
    you need your smtp host address and smtp user name and password to send emails out.
    and yes the user name and password are the smtp username and password for authentication
    regards
    shyam

Maybe you are looking for

  • Migrate Oracle EBS 12.1.3 from Microsoft Windows 2003 32-Bit to Linux

    Hi We are currently using Oracle EBS 12.1.3 on Microsoft Windows 2003 32-Bit. We are planning to migrate to linux. I have gone through the certification matrix and the following versions certified with Oracle EBS 12.1.3 1. Linux x86 Oracle Linux 5 2.

  • Internet application problems since 10.5.6 update (probably DNS related)

    After applying the 10.5.6 update (Combo) I have found that a number of internet apps, e.g. Safari, Apple Mail (with HTML messages), NetNewsWire or Twitterrific work much slower than before. Safari needs a long time to load web pages, images in HTML m

  • Downloading attachments in Safari

    For about the last week, I can't download Word or PDF or .zip attachments in Gmail through Safari.  Nothing happens when I click on the Download arrow in an email attachment.   (The problem also exists in Firefox). Safari Preferences are set to open

  • OC-genie not working as i expected after bios update

    Hey guys, I have an P55-GD65 with an i7 860. It ran stable with oc genie on 3.55Ghz but after an bios update ocgenie only clocks to 2.98Ghz. Whats wrong, or what did i do wrong? Greetings.

  • Future of VO / Novell Teaming + Conferencing

    I looked at the Novell Teaming + Conferencing product, but it seems like some functionality of the current Virtual Office product will be missing. There is no mention of things like eGuide, e-mailintegration or ZENWorks integration. It has features l