Help transport .send(message) problem

I am getting an error at transport.send(message)
javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.AuthenticationFailedException After eleminating all lines the error is at transport.send(msg)
Please help - tell me what I have been doing wrong
My code - is java mail using a jsp
try{
     //Properties props = System.getProperties();
Properties props = new Properties();
Store store;
props.put("mail.smtp.host", "smtp.snet.yahoo.com");
props.put("mail.smtp.auth", "true");
Session s = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("[email protected]");
message.setFrom(from);
String toAddresses = request.getParameter("to");
message.addRecipients(Message.RecipientType.TO, toAddresses);
String ccAddresses = request.getParameter("cc");
message.setRecipients(Message.RecipientType.CC, ccAddresses);
String bccAddresses = request.getParameter("bcc");
message.setRecipients(Message.RecipientType.BCC, bccAddresses);
String subject = request.getParameter("subject");
message.setSubject(subject);
message.setSentDate(new Date());
String text = request.getParameter("text");
message.setText(text);
Transport.send(message); //error is here
%>

You are specifying authentication to be used, but you aren't supplying any authentication credentials, hence the AuthenticationFailedException.
You need to create an Authenticator class. If you just need simple username/password authentication, just create a class to handle this.
For example:
public class SimpleAuthenticator extends Authenticator {
  private String username;
  private String password;
  private PasswordAuthentication auth;
  public java.lang.String getPassword() {
    return password;
  public PasswordAuthentication getPasswordAuthentication() {
    if(auth == null) {
      auth = new PasswordAuthentication(username, password);
    return auth;
  public java.lang.String getUsername() {
    return username;
  public void setPassword(java.lang.String password) {
    password = password;
  public void setUsername(java.lang.String username) {
    username = username;
}Then, when you create the session:
SimpleAuthenticator auth = new SimpleAuthenticator();
auth.setUsername("yourusername");
auth.setPassword("yourpassword");And instead of
Session s = Session.getInstance(props,null);use
Session s = Session.getInstance(props,auth);

Similar Messages

  • I am not able to execute the transport.send(message)

    I am not able to execute the transport.send(message) when trying for sending mail. I am getting error like this : -
    javax.mail.SendFailedException: Sending failed;  nested exception is: javax.mail.MessagingException: Could not connect to SMTP host: 10.175.80.50, port: 25;  nested exception is: java.net.ConnectException: Connection timed out: connect
    Please help me on this to resolve this issue asap. thanks

    Hi Vinod,
    public void SendMail( )
        //@@begin SendMail()
              // Specify the host name of the mail server
              String host ="----
              IWDMessageManager messageMgr = wdControllerAPI.getComponent().getMessageManager();
              // Initialize Session
              Properties props = System.getProperties();
              props.put("mail.smtp.host", host);
              props.put("mail.smtp.auth", "true");
              Authenticator auth = new Auth();
              Session session = Session.getInstance(props, auth);
              // Create new MimeMessage
              MimeMessage message = new MimeMessage(session);          
              try
                    // Set the From Address
                    String from = wdContext.currentContextElement().getCtx_From();
                   message.setFrom(new InternetAddress(from));
                   //  Set the To Address
                   String to = wdContext.currentContextElement().getCtx_To();     
                   Address ar[] = new Address[1];
                   ar[0] = new InternetAddress(to);
                   message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
                   // Set the Subject
                   message.setSubject(wdContext.currentContextElement().getCtx_Subject());
                   //  Set the Text               
                   message.setText(wdContext.currentContextElement().getCtx_Text());            
                   Transport tr = session.getTransport("smtp");
                   tr.connect("Put again here Host Name", Port Noumber, "userid", "password");               
                   tr.sendMessage(message, ar);
              }catch (AuthenticationFailedException e){
                   messageMgr.reportException(e.toString(),false);
              }catch (AddressException e)     {
                   messageMgr.reportException(e.toString(),false);
              } catch (MessagingException e) {
                   messageMgr.reportException(e.toString(),false);
              }catch (Exception e){
                   messageMgr.reportException(e.toString(),false);
        //@@end
    And also create the class Auth() like
    public class Auth extends Authenticator {
         public PasswordAuthentication getPasswordAuthentication()
              String username = "userID";
              String password = "Passwod";     
              return new PasswordAuthentication(username,password);     
    Please check it i think i will work. Also please use constant value for the to, from, subject and text.

  • Transport.send(Message) sends mail but throws exception

    Is it possible in any scenario that Transport.send(Message) method deliveres the message successfully, but throws an exception also?
    Any help is appreciated. Thanks.

    Yes, but only if you've configured it to do so.
    See the javadocs for the com.sun.mail.smtp package for the property
    you can set to cause it to do that.
    If you haven't set that property and you're seeing that behavior, please provide
    more detail, including especially the protocol trace.

  • URGENT::Status returned by Transport.send() and problem with mail.smtp.host

    Hello,
    I am writing a code to send an email using JavaMail. I have added mail.jar and activation.jar in the classpath. Also I would like to mention that I am using Weblogic6.1 SP4.
    A bunch of questions:
    1. After calling Transport.send(), how do i know if the mail was sent successfully or not ?? Is there anyway I can handle that?
    2. I am using props.put(mail.smtp.host, <some-value>). What should be this <some-value> ?? Where can I get this value from??
    And is this value sufficient for the code to know that which server we are using for it? Do we need to give any URL/Port etc? How does this work?
    3. Is there anything else other than smtp host, username and password to be added to props?? Do we need to create a properties file??
    4. After doing these things, do I need to create a mail session in the Weblogic server also or is it a different method?
    Please help me in resolving these issues.
    Thanks

    Thanks for your kind answers, Dr. Clap..!!
    However, I will again like to ask u this:
    1. As i said that I installed Weblogic 6.1 in my local machine, can I use it as the mail server? As the server is local to my machine, i know that its only me who is the incharge of it. How do I know what smtp host to use.
    2. I am using this code:
    public callService(ServiceRequest request) throws Exception {
         EmailRequest req = (EmailRequest) request;
         Session session = null;
         MimeMessage msg = new MimeMessage(session);
         String accNum = req.getAccountNumber();
         String toAddress = req.getToAddress().trim();
         String fromAddress = generalConfig.FROM_EMAIL_ADDRESS;
         String subject = req.getSubject().trim();
         String message = req.getMessage().trim();
         String [] arrToAddress = null;
         String fileName = "./"+accNum+".htm";
         if (toAddress != null) {
    arrToAddress = convertToArray(toAddress);
         Properties props = System.getProperties();
         props.put("mail.smtp.host", "MYSERVER"); //STILL NEED TO FIGURE OUT WHAT VALUE TO PUT HERE
    session = Session.getDefaultInstance(props);
         setRecipientsTo(msg,arrToAddress);
         msg.setFrom(new InternetAddress(fromAddress));
         msg.setSubject(subject);
         msg.setText(message);
    MimeMultipart mp = new MimeMultipart();
    MimeBodyPart text = new MimeBodyPart();
         text.setDisposition(Part.INLINE);
         text.setContent(message, "text/html");
         mp.addBodyPart(text);
         MimeBodyPart file_part = new MimeBodyPart();
         File file = new File(fileName);
         FileDataSource fds = new FileDataSource(file);
         DataHandler dh = new DataHandler(fds);
         file_part.setFileName(file.getName());
         file_part.setDisposition(Part.ATTACHMENT);
         file_part.setDescription("Attached file: " + file.getName());
         file_part.setDataHandler(dh);
         mp.addBodyPart(file_part);
         msg.setContent(mp);
    Transport.send(msg); //send message
    In this code, like I am using Properties class, will this code work fine(as it is) even if I dont make any Properties text file?? or is it mandatory for me to make the properties text file and to add some values to it?
    I am sorry, I may sound a bit dumb, but I just need to learn it somehow.
    Thanks.
    P.S: convertToArray() and setRecipientsTo() are my own defined private methods.

  • Help on sending messages

    Ok tried to send a message with my Ipad2 to my contacts, will only let me send to contacts with imessage.
    I also have the iphone 4S and it will let me send message to all of my contacts.
    Do I have to change a setting on my iPad?
    Thanks for any help

    Hey docasman, 
    Welcome to the support forums!
    The error you are seeing is normal, all it means is that the list will be truncated meaning you will not be able to see the full list of people in the CC field but you can add more and it will send the message to all of them.
    -SR
    Come follow your BlackBerry Technical Team on twitter! @BlackBerryHelp
    Be sure to click Kudos! for those who have helped you.Click Solution? for posts that have solved your issue(s)!

  • Help with iphone message problems

    My daughter, husband and I have iphones.  When I send a message it also goes to their phones and vice versa.  Only seems to happen when I text other iphone owners whose contacts are NOT in my husband or daughters phone contacts. How can I stop my messages and their replies going to other phones?  We have all deleted icloud from our phones but it's not worked ...

    This is being caused by using the same Apple ID for iMessage, not by iCloud.  If can be fixed in a couple of ways:
    On all but one of the phones go to Settings>Messages>Send & Receive, tap the ID, sign out, then sign back in with a different ID (so they are all using a differet ID for iMessage).  Note: you can still share the same ID for purchasing in Settings>iTunes & App Stores; or
    On all of gthe phones go to Settings>Messages>Send & Receive and uncheck the email address(es) shown under "You can be reached by iMessage at".  Also uncheck anyone else's phone number, if present.

  • Need help with a messaging problem.

    Well i deleted a thread of texts from someone while they were texting me i guess and one of the messages came through but i can not open it. NOw everytime i get a message it says have two unread messages, but there is only one to open. And sometimes i can pull down the notification at the top and there will be the message but i can not open it or delete it. How can i get rid of it? & turning off the phone and taking the battery out does not help. Please help it is reallly annoying.
    Thanks

    If the message is locked press and hold the message to unlock in.  Then delete the message.  
    Then power the device off, then removed and replace the battery.   
    Deleting a single message
    While viewing a message thread, press and hold the message that you want to delete.
    If the message is locked, tap Unlock message on the options menu, and then press and
    hold the message to display the options menu again.
    Tap Delete message on the options menu.
    When prompted to confirm, tap OK.
    Deleting several message threads
    Press HOME , and then tap > Messages.
    On the All messages screen, press MENU, and then tap Delete.
    Select the message threads you want to delete.
    Tap Delete. Any locked messages will not be deleted.
    Power the device off, then removed and replace the battery.  

  • Help cannot send messages since latest update

    Need another update is I can send messages

    That anti virus? is it Nortons security suite? I think that is what comcast give their xfinity customers but I am not sure what everyone else gets.
    Assuming is is the Norton's product go into the firewall component and explicitly allow Thunderbird unrestricted access to the internet. Norton's product have a long history of blocking new releases of mail programs because the version number changed.
    Go onto the SMTP setting you have in the image and make sure each has a description entered.
    Now check in the account settings by clicking the account name in the list so you select the item about Server settings for each account and make sure the selected SMTP server is what you think it is. Now there is a description that will show in the list.

  • Sending mail problem (please help)

    I have downloaded all necessary components javamail-1_2.zip and jaf1_0_1.zip. I included them in my classpath too (activation.jar and mail.jar). I used Exchange Server 2000 as smtp server. But when i try sending an email the message appears like this:
    sending error cannot relay for sending [email protected]
    When i tried the same code in my ISP (www.mycgiserver.com) it work very fine. Here is the code. Where is the problem? Please help me...
    <%
    // Take massege properties
    String mBody = request.getParameter("mBody");
    String from1 = request.getParameter("from");
    String to1 = request.getParameter("to");
    String subject = request.getParameter("subject");
    Properties props = new Properties();
    props.put("ipNo.........:25", "smtp.mail.blah.com");
    Session s = Session.getInstance(props,null);
    Message message = new MimeMessage(s);
    InternetAddress from = new InternetAddress(from1);
    message.setFrom(from);
    InternetAddress to = new InternetAddress(to1);
    message.setRecipient(Message.RecipientType.TO, to);
    message.setText(mBody);
    message.setSubject(subject);
    Transport.send(message);
    %>

    the problem i feel is in your smtp relay and probably not in ur code . some smtp relay servers are configured such that they relay only on authentication or from a specific IP or from a specific subnet mask only to prevent spammers . check out the info on ur local relay server and also see other postings specific on relay ....that shud be of help i guess

  • 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);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • SENDING MAIL PROBLEM??IN MY COLLEGE PC

    Hi,
    This is the program i done in netbeans IDE 6.5 for sending email through javamail...its works perfectly in my home PC..[BUT ITS  NOT WORK IN MY COLLEGE] COULD YOU GIVE SUGGESTION REGARDING THIS..
    <%
    Properties props= new Properties();
    props.put("mail.transport.protocol","smtp");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.host","smtp.gmail.com");
    // pop3Props.setProperty("mail.pop3.port", "995");
    Authenticator auth=new MyAuthenticator(session.getAttribute("name").toString(),session.getAttribute("pass").toString());
    Session s=Session.getInstance(props, auth);
    MimeMessage message=new MimeMessage(s);
    InternetAddress from=new InternetAddress("[email protected]","XXXXXXXXX");
    message.setFrom(from);
    InternetAddress to =new InternetAddress(request.getParameter("to"));
    message.addRecipient(Message.RecipientType.TO,to);
    message.setSubject(request.getParameter("sub"));
    message.setText(request.getParameter("text"));
    Transport.send(message);
    %>
    ERROR::
    type Exception report
    message
    descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: javax.mail.MessagingException: Unknown SMTP host: smtp.gmail.com;
    nested exception is:
         java.net.UnknownHostException: smtp.gmail.com
    root cause
    javax.mail.MessagingException: Unknown SMTP host: smtp.gmail.com;
    nested exception is:
         java.net.UnknownHostException: smtp.gmail.com
    root cause
    java.net.UnknownHostException: smtp.gmail.com
    note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1_02 logs.

    Thanks Mr.Drclap
    yeah i ask my sys administrator..this is problem of smtp server in my college server...
    thats why i can send any message through java mail...
    Bye..

  • Sending Email problem in webdynpro Application

    Hi all,
          I have the written following coding to send a mail.It was working fine till we upgrade our mailing server to Exchange server2007.
      Properties properties = new Properties();
       String SMTPIPAddress = "mail.exchange.com"
       String SMTPAddress = "mail.smtp.host";
        String mailId = "[email protected]";
        Session session;
        Provider p;     
        properties = System.getProperties();               
        properties.put(SMTPAddress, SMTPIPAddress);
        session = Session.getDefaultInstance(properties, null);
        Message message = new MimeMessage(session);               
        message.setFrom(new InternetAddress("[email protected]"));     
        message.addRecipient(Message.RecipientType.TO,
                                                       new InternetAddress(mailId));
        message.setSubject("Conference");           
        message.setText(strMailBody.toString());          
        Transport.send(message);
    Now I am geeting the following error.
          Exception : Sending failed;  nested exception is:  
           javax.mail.MessagingException: 530 5.7.1 Client was not authenticated 
    When I approahed the Admin people for the above error, since some relay must opened to receive the mail, they said it cannot be done in the exchange server.
    Is there any other way to send mail (different codings)
    Thanks in advance
    Ponnusamy P

    Hi Ponnusamy,
    First of all, use
    Session.getInstance()
    instead of
    Session.getDefaultInstance()
    <i>Since the default session is potentially available to all code executing in the same Java virtual machine, and the session can contain security sensitive information such as user names and passwords, access to the default session is restricted.</i>
    Second, I forgot, <i>To use SMTP authentication you'll need to set the mail.smtp.auth property [...]</i>. See also <a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html">com.sun.mail.smtp (JavaMail API documentation)</a>.
    Everything together becomes
    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.host", "mail.exchange.com");
    Session session = Session.getInstance(props, new MyAuthenticator());
    BTW, does the <i>AuthenticationFailedException</i> contain any additional information that indicates why authentication failed?
    Just note that JavaMail supports <i>SMTP Authentication (RFC 2554) using the LOGIN, PLAIN, and DIGEST-MD5 mechanisms [...] When using DIGEST-MD5 authentication, you'll also need to supply an appropriate realm; your mail server administrator can supply this information. You can set this using the mail.smtp.sasl.realm property, [...]</i>.
    So only LOGIN, PLAIN and DIGEST-MD5 are supported. It's very well possible your Exchange server is configured to support only NTLM and I can imagine your Exchange admin won't allow LOGIN authentication due to security reasons.
    And a last remark. <i>If your username is foo, your mailbox name is Foo.Bar and your server is FUBAR, your username for connecting to your mailbox is not foo. Instead, it would be FUBAR\foo\Foo.Bar</i>.
    Kind regards,
    Sigiswald

  • TS2755 Hi all, I bought one iphone and 3 ipads, i set up all on one apple ID. Now i have a problem when using messages: when sending message from one device it appears again on screen from the other 3 devices. I need help of how to set up messages on each

    Hi all, I bought one iphone and 3 ipads, i set up all on one apple ID. Now i have a problem when using messages: when sending message from one device it appears again on screen from the other 3 devices. I need help on how to set up messages on each device separately and to start using messages app on each device independently. Thanks

    search google for "iphone remove picture from contact"

  • I'm having some problems wiht Firefox, for example; Youtube isn't loading right, Facebook won't let me send messages, search up people, and this website i made wont load right also. I've re-installed and updated it but still the same problems. Any help?

    I'm having some problems wiht Firefox, for example; Youtube isn't loading right, Facebook won't let me send messages, search up people, and this website i made wont load right also. I've re-installed and updated it but still the same problems. Any help?

    Because I know enough to be dangerous...  I was trying to extend the two outside columns down....  Instead of just using faux columns which I have fixed since I posted the question.
    The other link problem is the left sidebar links.  When you go to the event photos page I have a repeat of the sidebar links that are on the newsletter page.  I used named anchors on the newsletter page to link to the particular article.  From the Event Photos page the links look like this:
    <a href="1112Visions_Iss1.html/#puzzle" target="_self">[Puzzle]</a>
    The problem I am having is that some of these go to the newsletter page and the anchor and some do not (I get an error message saying it  can't find the page).  To add to the problem is that when we choose say the President's Message, when it goes to the newsletter page and the correct anchor, the newsletter page is missing all the links to the graphics... the photos are missing the graphic for the faux columns is missing.  It makes no sense.  When I preview the newsletter page from Dreamweaver everything shows up fine.
    I do not know if all of this is being caused because I haven't posted this stuff to the site or what.  I've tried re-booting both the browser and Dreamweaver, dumping the cache and still the same nonsense.
    Got any ideas?

  • Mail can't send messages: Doesn't allow fix the problem either: Help plz.

    Hi all,
    Mail doesn't allow me to send messages through my recent created aim.com account
    I'm trying to fix the problem by changing smtp server configuration but it gives me the message:
    "The servers marked with alert icons are in conflict and cannot be saved.
    Two servers cannot share the same address and authentication settings.
    Resolve the conflicts and try again."
    There are no icons whatsoever and deleting any similar server won't take effect because Mail WON'T save the changes.
    When clicking "ok" to save changes, Mail will throw the same message quoted above. So I have to click "Cancel"
    Any idea to solve this issue?
    Thank you.

    http://support.apple.com/kb/TS3234

Maybe you are looking for

  • Mid 2011 iMac won't boot in any mode.

    Hello, Last ast week in the middle of a deadline my imac crashed. I was in the middle of a Pro Tools session and the next thing my mouse icon turns into a series of dots and everything freezes. So, I rebooted and since then I haven't been able to get

  • How to read file asychronous and show progress bar??

    Hello Everyone, I am new here and this is my first post here. I made a desktop application in Adobe flex builder 3. In the application I took the path of a folder and merge all the file present in that folder in a new file. I want to show the progres

  • Different order unit for different plant

    Hi, I ahve a material whose base unot of measure is kgs. Its purchase order unit for plant 1000 is Tonnes, and I want to have a different purchase order unit say LBS for plant 1100. Is it possible? Please advice. Regards, Vengal Rao.

  • JMS over SSL ?

    Hi, I am trying to use JMS over SSL on WebLogic 6.1 sp2 server. But it doesn't seem to work. Anybody tried it and got it to work? Here is my code (cut and pasted for a WLS document) to obtain a secure context: ht.put(Context.SECURITY_PRINCIPAL, "syst

  • Sales order type

    Dear all We have a deemed export order (Zabc) in domestic plant but no such order is available in EOU Plant. THis order type is required when we need to sell to a Domestic customer having an EOU unit. This means the taxes 8, 2 & 1 are exempted. Only