Sending mail to yahoo using javamail

hello,
i have a javamail code which able to send mail within my domain (mailserver ) .
but when i try to send mail to any yahoo id then i get following error :--
javax.mail.SendFailedException: Invalid Addresses;
please, anyone help me ; what should i do modification in my existing code for sending mail to yahoomail account.
the code which is working properly for my doamin is:--
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SendMailUsage {
public static void main(String[] args) {
// SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
String to = "[email protected]";
String from = "[email protected]";
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
String host = "172.13.2.48";
// Create properties for the Session
Properties props = new Properties();
// If using static Transport.send(),
// need to specify the mail server here
props.put("mail.smtp.host", host);
// To see what is going on behind the scene
props.put("mail.debug", "false");
// Get a session
Session session = Session.getInstance(props);
try {
// Get a Transport object to send e-mail
Transport bus = session.getTransport("smtp");
bus.connect();
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test E-Mail through mojax developers");
msg.setSentDate(new Date());
// Set message content and send
setTextContent(msg);
msg.saveChanges();
bus.sendMessage(msg, address);
bus.close();
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
// How to access nested exceptions
while (mex.getNextException() != null) {
// Get next exception in chain
Exception ex = mex.getNextException();
ex.printStackTrace();
if (!(ex instanceof MessagingException)) break;
else mex = (MessagingException)ex;
// A simple, single-part text/plain e-mail.
public static void setTextContent(Message msg) throws MessagingException {
// Set message content
String mytxt = "this mail is generated by java";
msg.setText(mytxt);
// Alternate form
msg.setContent(mytxt, "text/plain");
} //End of class

Turn on session debugging to get the protocol trace. Your mail server
is probably saying more about why the send failed than what you've
included here.
Then read the FAQ for likely problems.

Similar Messages

  • Having problem sending mail to yahoo using a yahoo id(SendMailException)

    Hi, I read almost all the post's related to javamail,but none of them seems to help me, and hence the reason for this post,
    i've written a simple application(with reference to the one implemented on sun's site) that sends a message to a yahoo id using a yahoo id,
    meaning
    [email protected](recepient) and [email protected](sender)
    the code is given below:
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import javax.mail.Authenticator;
    public class MailSender
         String host = "smtp.mail.yahoo.com";
         String from = "[email protected]";
         String to = "[email protected]";
         public void sendMessage()
              try
                   Properties props = System.getProperties();
                   props.put("mail.smtp.host", host);
                   props.put("mail.smtp.auth","true");
                   Authenticator auth = new MyAuthenticator();
                   Session session = Session.getInstance(props,auth);
                   session.setDebug(true);
                   MimeMessage message = new MimeMessage(session);
                   message.setFrom(new InternetAddress(from));
                   message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
                   message.setSubject("Hello JavaMail");
                   message.setText("Welcome to JavaMail");
                   message.saveChanges(); // implicit with send()
                   Transport.send(message);
              catch(Exception e)
                   System.out.println("Sorry could not complete your Request, you have an error "+ e);
                   e.printStackTrace();
         public static void main(String args[])     
              MailSender ms= new MailSender();
              ms.sendMessage();
         private class MyAuthenticator extends Authenticator
         public PasswordAuthentication getPasswordAuthentication() {
              return new PasswordAuthentication("someoneelse","password");
    It compiles but when i execute it i get a nested exception
    nested exception is:
    javax.mail.AuthenticationFailedException
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
    javax.mail.AuthenticationFailedException
    at javax.mail.Transport.send0(Transport.java:218)
    at javax.mail.Transport.send(Transport.java:80)
    at MailSender.sendMessage(MailSender.java:32)
    at MailSender.main(MailSender.java:45)
    Does anyone know a solution to this problem?

    Sure, you can put a local mail server on ur machine to test out sending and receiving in javamail. There r several mail server implementations out there, I personally prefer James (available at http://apache.org) It is pure java based mail server providing full POP3 and SMTP functionality.
    Once u configure a local mail server, u can use emailids like xyz@localhost or acme@localhost

  • Urgent!!!! Problem in sending mail through yahoo mail server

    Hi
    I have a yahoo account and I want to send email through yahoo mail server
    using my java program. My program supports SMTP server authentication.
    But when I connect to the yahoo mail server(smtp.mail.yahoo.com) I got this error
    javax.mail.MessagingException: 521 yahoo.com closing transmission channel. You
    must be pop-authenticated before you can use this smtp server, and you must use
    your yahoo mail address for the Sender/From field.
    This is my program
    import javax.mail.*;
    import java.util.*;
    import javax.mail.internet.*;
    import javax.mail.event.*;
    import java.io.*;
    public class JavaMailUserAgent
         Properties properties;
         Session session;
         Message message;
         JavaMailUserAgent(String mailHost,String smtpUsername,String smtpPassword) throws Exception
              properties=new Properties();
              properties.put("mail.smtp.host",mailHost);
              ServerAuthenticate auth=new ServerAuthenticate(smtpUsername,smtpPassword);
              session=Session.getInstance(properties,auth);
              message=new MimeMessage(session);
         } //**********************************************************************end constructor
         void sendMail(String messageFrom,String messageTo,String subject,String messageBody) throws Exception
              properties.put("mail.from",messageFrom);
              InternetAddress[] address={ new InternetAddress(messageTo) };
              message.setFrom(new InternetAddress(messageFrom));
              message.setRecipients(Message.RecipientType.TO,address);
              message.setSubject(subject);
              message.setContent(messageBody,"text/plain");
              Transport transport=session.getTransport(address[0]);
              transport.addConnectionListener(new ConnectionHandler());
              transport.addTransportListener(new TransportHandler());
              transport.connect();
              transport.sendMessage(message,address);
         } //*************************************************************************end function
    } //*************************************************************************************end main
    class ConnectionHandler extends ConnectionAdapter
         public void opened(ConnectionEvent e)
              System.out.println("connection opened");
         public void disconnected(ConnectionEvent e)
              System.out.println("connection disconnected");
         public void closed(ConnectionEvent e)
              System.out.println("connection closed");
    } //*************************************************************************************end main
    class TransportHandler extends TransportAdapter
         public void messageDelivered(TransportAdapter e)
              System.out.println("message delivered");
         public void messageNotDelivered(TransportAdapter e)
              System.out.println("message NOT delivered");
         public void messagePartiallyDelivered(TransportAdapter e)
              System.out.println("message partially delivered");
    } //*************************************************************************************end main
    class ServerAuthenticate extends Authenticator
         String smtpUsername = null;
         String smtpPassword = null;
         public ServerAuthenticate(String username, String password)
              smtpUsername = username;
              smtpPassword = password;
         protected PasswordAuthentication getPasswordAuthentication()
              return new PasswordAuthentication(smtpUsername,smtpPassword);
    } //*************************************************************************************end main
    I use this code to call the program.
    JavaMailUserAgent jmail=new JavaMailUserAgent("smtp.mail.yahoo.com","my_yahoo_username","my_yahoo_password");
    jmail.sendMail("[email protected]","[email protected]","test subject","test message");
    Could you pls tell me why do I get this error eventhough My program has server authentication.
    Is this my program error.Please Helpl me what to do to correct this problem.
    Please include a sample code
    thanks for listening
    sabu

    I have used the code below to send mail from yahoo account,but I got the error message like below,what I should configure in pop3 of yahoo account????
    import javax.mail.*;
    import java.util.*;
    import javax.mail.internet.*;
    import javax.mail.event.*;
    import java.io.*;
    public class JavaMailUserAgent
    Properties properties;
    Session session;
    Message message;
    JavaMailUserAgent(String mailHost,String smtpUsername,String smtpPassword) throws Exception
    properties=new Properties();
    properties.put("mail.smtp.host",mailHost);
    ServerAuthenticate auth=new ServerAuthenticate(smtpUsername,smtpPassword);
    session=Session.getInstance(properties,auth);
    message=new MimeMessage(session);
    //**********************************************************************end constructor
    void sendMail(String messageFrom,String messageTo,String subject,String messageBody) throws Exception
    properties.put("mail.from",messageFrom);
    InternetAddress[] address={ new InternetAddress(messageTo) };
    message.setFrom(new InternetAddress(messageFrom));
    message.setRecipients(Message.RecipientType.TO,address);
    message.setSubject(subject);
    message.setContent(messageBody,"text/plain");
    Transport transport=session.getTransport(address[0]);
    transport.addConnectionListener(new ConnectionHandler());
    transport.addTransportListener(new TransportHandler());
    transport.connect();
    transport.sendMessage(message,address);
    } //*************************************************************************end function
    } //*************************************************************************************end main
    class ConnectionHandler extends ConnectionAdapter
    public void opened(ConnectionEvent e)
    System.out.println("connection opened");
    public void disconnected(ConnectionEvent e)
    System.out.println("connection disconnected");
    public void closed(ConnectionEvent e)
    System.out.println("connection closed");
    } //*************************************************************************************end main
    class TransportHandler extends TransportAdapter
    public void messageDelivered(TransportAdapter e)
    System.out.println("message delivered");
    public void messageNotDelivered(TransportAdapter e)
    System.out.println("message NOT delivered");
    public void messagePartiallyDelivered(TransportAdapter e)
    System.out.println("message partially delivered");
    } //*************************************************************************************end main
    class ServerAuthenticate extends Authenticator
    String smtpUsername = null;
    String smtpPassword = null;
    public ServerAuthenticate(String username, String password)
    smtpUsername = username;
    smtpPassword = password;
    protected PasswordAuthentication getPasswordAuthentication()
    return new PasswordAuthentication(smtpUsername,smtpPassword);
    public static void main(String str[])throws Exception
    JavaMailUserAgent jmail=new
    JavaMailUserAgent("smtp.mail.yahoo.com","[email protected]","passwordd");
    jmail.sendMail("[email protected]","[email protected]","test subject","test message");
    ERROR:
    E:\mail\javamail\servlet>java ServerAuthenticate
    connection opened
    Exception in thread "main" javax.mail.MessagingException: 530 authentication req
    uired - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html
    at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:879)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:599)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(Compiled Code)
    at JavaMailUserAgent.sendMail(JavaMailUserAgent.java:58)
    at ServerAuthenticate.main(JavaMailUserAgent.java:131)
    How Could I rectyfy the above error ?????
    Regards,
    Mahesh.

  • HT4519 can't send mail with yahoo in wifi mode

    can't send mail with yahoo in wifi mode only
    I receive this message ' appl.smtp.mail.yahoo.com' expired
    I have deleted my account and recreated. Same problem

    Nevermind...used my isp's outgoing mail server and it worked...
    -Ed

  • Can i send mail to yahoo from work flow

    can i send mail to yahoo from work flow  if it is possible how do i do that ? is this program enough if yes how do i do that ? do i need to write or change any coding

    Hi Neo ,
    You can use Function module  'SO_OBJECT_SEND' from your BO Method.
      For this Function module to work Email configuration should be done for 
      external  addresses..Please check with your Basis team for necessary config.
    Thank you
    Srinivas

  • Sending mail in java using sendmail programme of lynix

    Hi,
    How can I send mail using Java and lynux "sendmail" programme located at i.e sendmail: /usr/sbin/sendmail.
    I don't want to use JavaMail API for sending. I want to use sendmail of lynix server. Plz help me. It's very uregent.
    Regards,
    Devom

    Hey Guys, here is the workaround for sending mails in java through javamail program of linux/unix:
    step 1 - Create a shell script which sends the mail using the 'sendmail' program. I have written below code in my shell script:
    #!/bin/sh
    #script to send simple email
    # email subject
    SUBJECT="Test Subject"
    # Email To ?
    EMAIL="[email protected],[email protected]"
    # Email text/message. This file will be automatically created and all text will be appended in it.
    EMAILMESSAGE="/tmp/emailmessage.txt"
    echo "This is a sample mai text."> $EMAILMESSAGE
    echo "And this is a also." >>$EMAILMESSAGE
    echo " " >>$EMAILMESSAGE
    echo " " >>$EMAILMESSAGE
    echo "Thanks & Regards," >>$EMAILMESSAGE
    echo "--Your Name" >>$EMAILMESSAGE
    mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
    So create this script and save it as 'sendmail.sh' name in the same directory where you are executing your main java class. Please also note that this file should have full executable permissions for the program which is using this file.
    Step 2- Here is my Java code that executed this shell script:
    public void sendEmail()
    String operatingSystemProp = "os.name";
    String operatingSystemName = System.getProperty(operatingSystemProp);
    if(!operatingSystemName.startsWith("Windows"))
    String cmd = "./sendmail.sh";//unix shell script
    try
         Runtime.getRuntime().exec(cmd);
    }catch (Exception e)
         e.printStackTrace();
    You just need to call this method in your java code. This method will actually pick that shell script in runtime and will execute it, the rest will be handled by the shell script itself.
    So this workaround works fine for me and now I am sending mails through my java program using sendmail.
    Cheers!

  • Sending mails with attachments using oracle 8i

    Hi,
    Could anybody please send a sample code for sending mails
    with attachments using oracle 8i.
    Thanks in advance

    For oracle8i there is an example package from OTN:
    http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/Utl_Smtp_Sample.html
    You have to re-write the package a bit to work it with BLOBs instead of RAW attachments, but that should be no problem
    Hop this helps,
    Michiel

  • I am not able to send mails through Yahoo APP.It gives me an error msg :"the sender address has ben rejected by the server ".I tried adding username and password in the SMTP server settings,But those optiopns are greyed out.

    I am not able to send mails through Yahoo APP. It gives me an error msg :"the sender address has ben rejected by the server ".
    I tried adding username and password in the SMTP server settings,But those optiopns are greyed out.
    So, i am not able to enter anything in fields under SMTP server settings

    You probably have changing settings disabled in Restrictions.

  • I can't send emails through Yahoo using Firefox. Already contacted Yahoo and they don't know why it's happening.

    I can't send emails through Yahoo using Firefox. Already contacted Yahoo and they don't know why it's happening.
    == This happened ==
    Every time Firefox opened
    == a month agao

    I also cannot send email through Yahoo using Firefox 3.6.8. I can receive emails and surf the web just fine. I have also contacted Yahoo and have gotten no where.

  • By trying to send mail with yahoo smtp, i got " connexion lost" What to do?

    since firefox 3.04, it is impossible to send mails via Yahoo smtp servor : error message "connexion lost"
    == This happened ==
    Every time Firefox opened
    == urgrading

    I changed the connection security in Thunderbird from SSL/TLS to STARTTLS for the Yahoo SMTP account and I can now send mails without problem with the Eset IMAP checking enabled. Problem solved. Thank you

  • Sendmail sending mail to yahoo but not local domain

    Hi,
    I havent worked much on sendmail at all, and as I know it its already configured in Solaris 10 and we just have to put in the relevant entries of DNS etc to make it work. Now the problem is when I use the command mailx to send mail, it is sending it to addresses like yahoo and hotmail, but no email is received on the local addresses on local domain. Example:
    mailx -v [email protected] ----------------------> works, but
    mailx -v [email protected] ------------------> doesn't work (no email is received)
    Can someone please guide me as to what the issue could be? Thanks,
    Raza

    mailx -v [email protected] ------------------> doesn't work (no email is received)
    What does:
    /usr/lib/sendmail -v [email protected]
    reveal?
    alan

  • Sendmail sends mail to yahoo but not local domain

    Hi,
    I havent worked much on sendmail at all, and as I know it its already configured in Solaris 10 and we just have to put in the relevant entries of DNS etc to make it work. Now the problem is when I use the command mailx to send mail, it is sending it to addresses like yahoo and hotmail, but no email is received on the local addresses on local domain. Example:
    mailx -v [email protected] ----------------------> works, but
    mailx -v [email protected] ------------------> doesn't work (no email is received)
    Can someone please guide me as to what the issue could be? Thanks,
    Raza

    you will need to provide some additional info.
    What is your DS entry configured to in sendmail.cf this should be your mail bridge. Based on the fact that you can send to yahoo.com it sound like this is working.
    For local email need to check your domain entry /etc/resolv.conf. This needs to match your systems domain name. This file may also contain a SEARCH entry which would allow email to check multiple domains.
    You can also look at the sendmail log to see what sendmail is doing with the email request. Posting the output from mailx -v would help.
    Finally make sure that the sendmail daemon is running if you want your unix machine to receive in bound email.

  • HT1430 Can't send mail from yahoo on my iPhone 3G through AT&T

    I tried resetting the phone and it still won't send emails. It's not my yahoo account as it works from my iPad and my laptop. I'm trying to  til fall to buy a new phone so I can switch carriers...any ideas on how to fix this issue?

    Sorry for not being clear. Regarding the Hotmail, I can download the mail and even reply. The problem is, I cannot see the original email I am replying to. This makes responding to a long email difficult, as well as making corrections from the original email. Will setting up the iPad e-mail client to use POP to download my Hotmail rectify the problem I just explained? Thanks.
    It is Yahoo I cannot reply to at all. Any suggestions re: Yahoo?

  • C6-01- Cant send mail via yahoo mail

    I have set up my yahoo mail account on my Nokia C6-01. I receive mails as they should do. But I Cant send mail. When I compose a mail and try to send it it just stays in outbox. I have set the mailbox settings correctly. While my gmail account works fine to send mails. Mails are sent instantly. Is anyone else going thru this trouble? And I Cant set up the Ovi mail mailbox. It keeps telling me "unable to sign in" How shall I solve this problem?
    In Love With My C6-01:Now running on Nokia Belle!
    Solved!
    Go to Solution.

    Well, it works fine if you use Nokia messaging service. If you use the standard mailbox it has been failing. I have some reservations about Nokia messaging service and thats why I dont want to use it.
    In Love With My C6-01:Now running on Nokia Belle!

  • TS3899 Isses sending mail through yahoo and also iCloud. Apple says its a conflict w/ yahoo, but I have the issues w iCloud a well. Why?

    Difficulties sending mail. Especially when graphics are attached.... Extremely slow or not at all. I can receive just fine
    Apple says its a conflict w/ yahoo, but I have the same issues with iCloud. Why?

    Welcome to the Apple Community.
    In order to change your Apple ID or password for your iCloud account on your iOS device, you need to delete the account from your iOS device first, then add it back using your updated details. (Settings > iCloud, scroll down and hit "Delete Account")

Maybe you are looking for

  • What is new feature in Apple's new OS X Mountain Lion

    hello currently i have MA OSX  Hello i have just read some of feature of this new OS

  • How to set paragraph format in Pages?

    I'm a novelist.  I have had trouble setting and maintaining a paragraph format in Pages.  I've manually created a format then copied and pasted that format, but it doesn't maintain the indentations and spacing I want.  I've completely left Word, alth

  • How to delete "Shared Garageband Settings" & "My Garageband Settings" in Logic's library?

    Hey guys, Does anybody out there know how to delete the "Shared Garageband Settings" & "My Garageband Settings" in the library tab? Basically, I just bought Logic Pro and all it's additional content and there's two folders (read above) which have one

  • Occupies more space

    I down loaded the Oracle 10gR2 for Windows Vista and installed in my Note book. It installed correctly. But when I inserted data into a table using FOR loop, it occupies more than 15 GB of space. So, should I modify any parameter or what is the step

  • LOGIC PRO - problem when recording guitar

    Hi, So I am having the following problem as I plug in my guitar in the interface (yamaha) and then into logic pro. I manage to record in the AUDIO track for some time, about a minute or so, and then I always hear a strange scratching sound and the gu