Problems while sending mail using java mail

hi all,
the following are the errors i get while sending a mail from my smtp local host-
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);
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);
msg.setRecipients(Message.RecipientType.TO, address);
System.out.println("fc");
msg.setSubject(msgSubject);
System.out.println("fvf");
if(!sendmultipart)
// send a plain text message
msg.setContent(msgText, "text/plain");
System.out.println("fif");
else
System.out.println("felsd");
// 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();
System.out.println("fconn");
          //transport.sendMessage(msg,msg.getAllRecipients());
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();     
//Transport.send(msg);
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 dont understand what the problem is..inspite of having the right code..
i guess some firewall problem..
can somebody help me please..il be highly obliged..thanks..

hi all,
the following are the errors i get while sending a mail from my smtp local host-
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);
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);
msg.setRecipients(Message.RecipientType.TO, address);
System.out.println("fc");
msg.setSubject(msgSubject);
System.out.println("fvf");
if(!sendmultipart)
// send a plain text message
msg.setContent(msgText, "text/plain");
System.out.println("fif");
else
System.out.println("felsd");
// 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();
System.out.println("fconn");
          //transport.sendMessage(msg,msg.getAllRecipients());
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();     
//Transport.send(msg);
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 dont understand what the problem is..inspite of having the right code..
i guess some firewall problem..
can somebody help me please..il be highly obliged..thanks..

Similar Messages

  • Problem in sending messages using java mail api

    Hi All,
    I have a problem in sending messages via java mail api.
    MimeMessage message = new MimeMessage(session);
    String bodyContent = "ñSunJava";
    message.setText (bodyContent,"utf-8");using the above code its not possible for me to send the attachment. if i am using the below code means special characters like ñ gets removed or changed into some other characters.
    MimeBodyPart messagePart = new MimeBodyPart();
                messagePart.setText(bodyText);
                // Set the email attachment file
                MimeBodyPart attachmentPart = new MimeBodyPart();
                FileDataSource fileDataSource = new FileDataSource("C:/sunjava.txt") {
                    public String getContentType() {
                        return "application/octet-stream";
                attachmentPart.setDataHandler(new DataHandler(fileDataSource));
                attachmentPart.setFileName(filename);
                Multipart multipart = new MimeMultipart();
                multipart.addBodyPart(messagePart);
                multipart.addBodyPart(attachmentPart);
                message.setContent(multipart);
                Transport.send(message);is there any way to send the file attachment with the body message without using MultiPart java class.

    Taken pretty much straight out of the Javamail examples the following works for me (mail read using Thunderbird)        // Define message
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            // Set the 'to' address
            for (int i = 0; i < to.length; i++)
                message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    // Set the 'cc' address
    for (int i = 0; i < cc.length; i++)
    message.addRecipient(Message.RecipientType.CC, new InternetAddress(cc[i]));
    // Set the 'bcc' address
    for (int i = 0; i < bcc.length; i++)
    message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc[i]));
    message.setSubject("JavaMail With Attachment");
    // Create the message part
    BodyPart messageBodyPart = new MimeBodyPart();
    // Fill the message
    messageBodyPart.setText("Here's the file ñSunJava");
    // Create a Multipart
    Multipart multipart = new MimeMultipart();
    // Add part one
    multipart.addBodyPart(messageBodyPart);
    // Part two is attachment
    for (int count = 0; count < 5; count++)
    String filename = "hello" + count + ".txt";
    String fileContent = " ñSunJava - Now is the time for all good men to come to the aid of the party " + count + " \n";
    // Create another body part
    BodyPart attachementBodyPart = new MimeBodyPart();
    // Get the attachment
    DataSource source = new StringDataSource(fileContent, filename);
    // Set the data handler to this attachment
    attachementBodyPart.setDataHandler(new DataHandler(source));
    // Set the filename
    attachementBodyPart.setFileName(filename);
    // Add this part
    multipart.addBodyPart(attachementBodyPart);
    // Put parts in message
    message.setContent(multipart);
    // Send the message
    Transport.send(message);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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 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.

  • 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

  • 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.

  • 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

  • Problem while sending Abap list to mail in the background

    Hi all,
    I am sending abap list to email in the background.
    My code as folllows:
    DATA: so_ali LIKE solisti1 OCCURS 100 WITH HEADER LINE.
      DATA: listobject LIKE abaplist OCCURS 0 WITH HEADER LINE.
      DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
      DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
      DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
      DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
      DATA: doc_chng LIKE sodocchgi1.
      DATA: tab_lines LIKE sy-tabix.
      DATA: lt_user TYPE soud3 OCCURS 0 WITH HEADER LINE.
    *Start of modification Tix 14411 for transport request D82K929044
      DATA: it_user like SODLIENTI1 occurs 0 with header line.
    *End of modification for Tix 14411 for transport request D82K929044
    CLEAR: listobject, so_ali, objpack, objhead, objtxt, reclist, doc_chng.
      REFRESH :
         listobject, so_ali, objpack, objhead, objtxt, reclist.
    creation of the document to be sent
      doc_chng-obj_name = 'BOFAREPORT'.
      WRITE sy-datum TO doc_chng-obj_descr.
      CONCATENATE 'Bank Activity Report for :'(025)
              company_itab_tr-company_code '-' doc_chng-obj_descr INTO
              doc_chng-obj_descr.                               "AN052799
      objtxt = 'This is the bank activity report received for'(026).
      APPEND objtxt.
      CONCATENATE company_itab_tr-company_code '-'
                  company_itab_tr-company_name '-'
                  company_itab_tr-company_city INTO
                  objtxt.
      APPEND objtxt.
      WRITE sy-datum TO objtxt.
      CONCATENATE 'Date Received : '(027) objtxt INTO objtxt.
      APPEND objtxt.
      WRITE sy-uzeit TO objtxt.
      CONCATENATE 'Time Received : '(028) objtxt INTO objtxt.
      APPEND objtxt.
      DESCRIBE TABLE objtxt LINES tab_lines.
      READ TABLE objtxt INDEX tab_lines.
      doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
    Creation of the entry for the compressed document
      CLEAR objpack-transf_bin.
      objpack-head_start = 1.
      objpack-head_num = 0.
      objpack-body_start = 1.
      objpack-body_num = tab_lines.
      objpack-doc_type = 'RAW'.
      APPEND objpack.
    Creation of the document attachment
      CALL FUNCTION 'SAVE_LIST'
        EXPORTING
          list_index         = '0'
        TABLES
          listobject         = listobject
        EXCEPTIONS
          list_index_invalid = 1
          OTHERS             = 2.
      CALL FUNCTION 'TABLE_COMPRESS'       "Schneller Tabellencopy
           TABLES
                in         = listobject
                out        = so_ali.
      DESCRIBE TABLE so_ali LINES tab_lines. "objbin
      objhead = 'BOFA-REPORT'. APPEND objhead.
    Creation of the entry for the compressed attachment
      objpack-transf_bin = 'X'.
      objpack-head_start = 1.
      objpack-head_num = 1.
      objpack-body_start = 1.
      objpack-body_num = tab_lines.
      objpack-doc_type = 'ALI'.
      objpack-obj_name = 'BOFAREPORT'.
      objpack-obj_descr = 'Bank Activity Report'.
      objpack-doc_size = tab_lines * 255.
      APPEND objpack.
    Completing the recipient list
      SELECT * FROM zwfi_yefap_paypr WHERE
                           bukrs = company_itab_tr-company_code.
        IF NOT  ( zwfi_yefap_paypr-list1 IS INITIAL ).
          clear it_user[].
          CALL FUNCTION 'SO_DLI_READ_API1'
           EXPORTING
             DLI_NAME                         = zwfi_yefap_paypr-list1
          DLI_ID                           = ' '
             SHARED_DLI                       = 'X'
        IMPORTING
          DLI_DATA                         =
           TABLES
             DLI_ENTRIES                      = it_user
           EXCEPTIONS
             DLI_NOT_EXIST                    = 1
             OPERATION_NO_AUTHORIZATION       = 2
             PARAMETER_ERROR                  = 3
             X_ERROR                          = 4
             OTHERS                           = 5
          IF SY-SUBRC = 0.
            loop at it_user.
              if it_user-member_typ = 'A'.
                reclist-receiver = it_user-member_adr.
                reclist-rec_type = 'U'.
                reclist-com_type = 'INT'.
                reclist-notif_del = 'X'.
                reclist-notif_ndel = 'X'.
                append reclist.
              elseif it_user-member_typ = ''.
                reclist-receiver = it_user-member_nam.
                reclist-rec_type = 'B'.
                reclist-express = 'X'.
                append reclist.
              Endif.
            endloop.
          ENDIF.
        ENDIF.
        IF NOT ( zwfi_yefap_paypr-list2 IS INITIAL ).
          clear it_user[].
          CALL FUNCTION 'SO_DLI_READ_API1'
           EXPORTING
             DLI_NAME                         = zwfi_yefap_paypr-list2
          DLI_ID                           = ' '
             SHARED_DLI                       = 'X'
        IMPORTING
          DLI_DATA                         =
           TABLES
             DLI_ENTRIES                      = it_user
           EXCEPTIONS
             DLI_NOT_EXIST                    = 1
             OPERATION_NO_AUTHORIZATION       = 2
             PARAMETER_ERROR                  = 3
             X_ERROR                          = 4
             OTHERS                           = 5
          IF SY-SUBRC = 0.
            loop at it_user.
              if it_user-member_typ = 'A'.
                reclist-receiver = it_user-member_adr.
                reclist-rec_type = 'U'.
                reclist-com_type = 'INT'.
                reclist-notif_del = 'X'.
                reclist-notif_ndel = 'X'.
                append reclist.
              elseif it_user-member_typ = ''.
                reclist-receiver = it_user-member_nam.
                reclist-rec_type = 'B'.
                reclist-express = 'X'.
                append reclist.
              Endif.
            endloop.
          ENDIF.
        endif.
      ENDSELECT.
      CLEAR error_text.
    Sending the document
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = doc_chng
          put_in_outbox              = 'X'
          COMMIT_WORK                = 'X'
       TABLES
          packing_list               = objpack
          object_header              = objhead
          contents_bin               = so_ali  "objbin
          contents_txt               = objtxt
          receivers                  = reclist
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          operation_no_authorization = 4
          OTHERS                     = 99.
      CASE sy-subrc.
        WHEN 0.
          write: / 'Result of the send process:'.
          LOOP AT reclist.
            write: / reclist-receiver(48), ':'.
            IF reclist-retrn_code <> 0.
              write 'The document was sent'.
            else.
              CONCATENATE 'The document could not be sent to : '(029)
                         reclist-receiver(48) INTO error_text.
            ENDIF.
          ENDLOOP.
        WHEN 1.
          error_text = text-030.
        WHEN 2.
          error_text = 'Document could not be sent to any recipient'(031).
        WHEN 4.
          error_text = 'No send authorization'(032).
        WHEN OTHERS.
          error_text = 'Error occurred while sending'(033).
      ENDCASE.
      IF NOT ( error_text IS INITIAL ).
        CONCATENATE 'Mail send Error : '(034) error_text INTO error_text.
       PERFORM WRITE_LOG(YEFAP_APERAK) USING ERROR_TEXT.
        PERFORM write_log(zwfi_yefap_bank_report) USING error_text.
      ENDIF.
      CALL FUNCTION 'LIST_FREE_MEMORY'
        TABLES
          listobject = listobject
        EXCEPTIONS
          OTHERS     = 1.
    When I excute the same program in the foreground, Attachment in the mail is showing all the pages of the report output.
    But when I excute the same program in the background only last page is shown in the mail attachemnt.
    I think the problem is with the function module SAVE_LIST function module.
    I replaced the SAVE_LIST function module with  LIST_TO_MEMORY and LIST_FROM_MEMORY function modules.
    It is also giving the same result.
    In the foreground excution email attachemnt showing all the pages and in the background excution only last page is shown in the attachemnt.
    I want all the pages dispalyed in the background mode excution in the email attachment.
    How to slove this issue.
    Thanks in advance.
    Raja

    I have seen this problem before.   Please have a look at this example program.  This works very well when ran in background as well as foreground
    * This program works in the background,
    report zrich_0003 .
    data: maildata like sodocchgi1.
    data: mailtxt like solisti1 occurs 10 with header line.
    data: mailrec like somlrec90 occurs 0 with header line.
    data: list type table of abaplist with header line.
    data: ascilines(1024) type c occurs 0 with header line.
    data: htmllines type table of w3html with header line.
    parameters: p_check.
    start-of-selection.
      submit zrich_0004 exporting list to memory and return.
      call function 'LIST_FROM_MEMORY'
           tables
                listobject = list
           exceptions
                not_found  = 1
                others     = 2.
      call function 'LIST_TO_ASCI'
           tables
                listobject         = list
                listasci           = ascilines
           exceptions
                empty_list         = 1
                list_index_invalid = 2
                others             = 3.
      call function 'WWW_HTML_FROM_LISTOBJECT'
           tables
                html       = htmllines
                listobject = list.
      clear: maildata, mailtxt, mailrec.
      refresh: mailtxt, mailrec.
      maildata-obj_name = 'TEST'.
      maildata-obj_descr = 'Test Subject'.
      loop at htmllines.
        mailtxt = htmllines.
        append mailtxt.
      endloop.
      mailrec-receiver = '[email protected]'.
      mailrec-rec_type = 'U'.
      append mailrec.
      call function 'SO_NEW_DOCUMENT_SEND_API1'
           exporting
                document_data              = maildata
                document_type              = 'HTM'
                put_in_outbox              = 'X'
           tables
                object_header              = mailtxt
                object_content             = mailtxt
                receivers                  = mailrec
           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.
      commit work.
      wait up to 2 seconds.
      submit rsconn01 with mode = 'INT'
                   with output = 'X'
                              and return.
    Regards,
    Rich Heilman

  • 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!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • 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.

  • Problem in retrieving email using java mail api

    hi,
    In my project,i am retrieving mails from a particular email id.
    I am able to retrieve the latest mails and save it in a folder in my system.
    The problem is whenever i run the program eventhough the most recently received mail in inbox is retrieved and saved,again it is retrieving the same one and saving it in the same folder(not repeating).
    I tried to check the newmessages in the inbox using the folder.hasNewMessage() method in java mail api,but the method is returning false only regardless new mail is there in inbox or not.
    I want to read the unread messages only.Dont want to retrieve the already read mails.
    I got the mail retrieving code from the below site.(sorry not posting the code because it is so long and having 4 classes)
    http://www.builderau.com.au/program/java/soa/Getting_the_mail_in_receiving_in_JavaMail/0,39024620,39228060,00.htm
    Can anyone tell me how to read unread mails in the inbox?
    Thanks a lot

    hi parvathi
    i think your mail program is receving mails using imap
    the imap is only receve the mail from server but the pop is deleting the mails after receving
    use the following sample code
    package com.sfrc.mail.pop;
    import javax.mail.*;
    import javax.mail.internet.*;
    import com.sun.mail.handlers.message_rfc822;
    import java.util.*;
    import java.io.*;
    * Owner: SFRC IT Solutions Pvt Ltd
    * Author:Arunkumar Subramaniam
    * Date :12-06-2006
    * File Name: AttachRecive.java
    public class AttachRecive
    public static void main(String args[])
    try
    String popServer="192.168.1.1";
    String popUser="pl";
    String popPassword="password";
    // Create empty properties
    Properties props = new Properties();
    // Get session
    Session session = Session.getDefaultInstance(props, null);
    // Get the store
    Store store = session.getStore("pop3");
    store.connect(popServer, popUser, popPassword);
    // Get folder
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_ONLY);
    // Get directory
    Message message =folder.getMessages();
    Multipart mp = (Multipart)message.getContent();
    for (int i=0, n=mp.getCount(); i<n; i++) {
    Part part = mp.getBodyPart(i);
    String disposition = part.getDisposition();
    // Close connection
    folder.close(false);
    store.close();
    catch (Exception ex)
    System.out.println("Usage: "
    +" popServer popUser popPassword");
    System.exit(0);
    Regards
    Arunkumar Subramaniam
    SFRC IT Solutions Pvt Ltd
    Chennai

  • 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

  • Problem while sending Abap list to mail

    Hi All,
    I am sending an abap list to mail using function module SO_NEW_DOCUMENT_ATT_SEND_API1.
    Report output is going to mail id but only last page is showing.
    The flow i followed in the code is as follows:
    First I used Function module SAVE_LIST
    Next I used Function module TABLE_COMPRESS
    And finally i used function module SO_NEW_DOCUMENT_ATT_SEND_API1
    Report output is going to mail id but last page is showingup.
    I want all the pages to show in the email.
    How it can be solved?
    Thanks in Advance,
    Raja

    Raja,
    Please provide your code that builds the ABAP List and the code that builds the mail package.

  • Problem: Error while sending Email.(Java Mail API)

    Hi to ALL
    I am trying to build Application to send Email
    Below code is primary code to send Email to other smtp host.
    & also debug information is as shown below.
    If possible, then please send the solution.
    -------------------------------Code :-----------------------------------------
    URLName urlN=new URLName("smtps://"+userNm+":"+passwd+"@"+host);
    Properties props = System.getProperties();
    Session session = Session.getDefaultInstance(props);
    session.setDebug(true);
    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(from));
    InternetAddress[] address= InternetAddress.parse(to, false);
    msg.setRecipients(MimeMessage.RecipientType.TO, address);
    msg.setSubject("subject");
    msg.setContent("messageSend Hi", "text/plain");
    Transport transport=session.getTransport(urlN);
    transport.connect();
    transport.sendMessage(msg, address);
    ---------- Java Run ----------
    DEBUG: setDebug: JavaMail version 1.3.2
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth false
    DEBUG SMTP: trying to connect to host "hostName", port 465, isSSL true
    220 smtp110.mail.mud.yahoo.com ESMTP
    DEBUG SMTP: connected to host "hostName", port: 465
    EHLO patil
    250-smtp110.mail.mud.yahoo.com
    250-AUTH LOGIN PLAIN XYMCOOKIE
    250-PIPELINING
    250 8BITMIME
    DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XYMCOOKIE"
    DEBUG SMTP: Found extension "PIPELINING", arg ""
    DEBUG SMTP: Found extension "8BITMIME", arg ""
    DEBUG SMTP: use8bit false
    MAIL FROM:<from email address>
    530 authentication required - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html
    com.sun.mail.smtp.SMTPSendFailedException: 530 authentication required - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html
    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 SendEmail2.<init>(SendEmail2.java:46)
    at SendEmail2.main(SendEmail2.java:23)
    Exception : com.sun.mail.smtp.SMTPSendFailedException: 530 authentication required - for help go to
    http://help.yahoo.com/help/us/mail/pop/pop-11.htmls
    -------------------------------------------------------------------------------------

    It's possible. It's only software, after all.
    But it's not easy. It effectively involves
    screen scraping the HTML pages.
    There used to be a third party JavaMail provider
    that did all the hard work, but it has disappeared.

  • 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