aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Getting  javax.mail.SendFailedException: Sending failed;  Please Help its Urgent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Getting  javax.mail.SendFailedException: Sending failed;  Please Help its Urgent" Watch "Getting  javax.mail.SendFailedException: Sending failed;  Please Help its Urgent" New topic
Author

Getting javax.mail.SendFailedException: Sending failed; Please Help its Urgent

lokesh pattajoshi
Ranch Hand

Joined: Jul 29, 2009
Posts: 130
I am using below programme to send mail but getting Exception Please help



public class SendEmail {

static Session session = null;

static{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
"userID@gmail.com",
"pswd");
}
});
session.setDebug(false);
}


public void sendMail(MailInfo mailInfo) {
try{
System.out.println("In sendMail Method"+session.toString() );
Message msg = new MimeMessage(session);

List recipientsList = mailInfo.getTOAddresses();
InternetAddress[] addressTo = new InternetAddress[recipientsList.size()];
for (int i = 0; i < recipientsList.size(); i++) {
addressTo[i] = new InternetAddress(((InternetAddress)recipientsList.get(i)).getAddress() );
}
System.out.println("addressTo " +addressTo);
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(mailInfo.getSubject() );
msg.setContent(mailInfo.getMessage() , "text/html");
Transport.send(msg);
}catch(Exception exception){
StringWriter sw=new StringWriter();
PrintWriter pw=new PrintWriter(sw);
exception.printStackTrace(pw);
System.out.println("MailServices :: sendMail("+mailInfo+") exception :"+sw.toString() );
}
}

public static void main(String args[]) throws Exception {

MailInfo mailInfo = new MailInfo();
mailInfo.setContentType(MailInfo.HTML_TEXT);
mailInfo.addTOAddress("userID@gmail.com","aaa");
mailInfo.setSubject("Subject");
mailInfo.setMessage("haha haha mtl message");

new SendEmail().sendMail(mailInfo);
System.out.println("Sucessfully Sent mail");
}

}
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.

You can edit your post by using the button.

Also, please see EaseUp.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please read ItDoesntWorkIsUseless and TellTheDetails: you wouldn't expect an auto mechanic to diagnose and solve a problem with your car without being able to look at the car. We're not at your machine and have no other information other than what you choose to share--without knowing what's happening, what you expected, what (if any) errors you received, and so on, it's impossible to help.

Post stack trace details, without them, anything we come up with is a guess. Line number(s), the actual exception message, and so on.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Sun's JavaMail FAQ has an entry on how to make it work with Gmail: http://java.sun.com/products/javamail/FAQ.html#gmail. It looks like your code doesn't do what's described there.


Ping & DNS - updated with new look and Ping home screen widget
lokesh pattajoshi
Ranch Hand

Joined: Jul 29, 2009
Posts: 130
Dear Ulf Dittmer thanks for your replay for any other smtp host also it is throwing javax.mail.MessagingException: can't determine local email address exception.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Did you actually read that FAQ entry and pay attention to the details?
lokesh pattajoshi
Ranch Hand

Joined: Jul 29, 2009
Posts: 130
Yes Dittmer i did not get any thing related to my Exception.Can you please tell me what are the jar files i have to include?
Still i am getting following exception kindly help me..

javax.mail.MessagingException: can't determine local email address
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19557
    
  16

Try setting the From address.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
i did not get any thing related to my Exception.Can you please tell me what are the jar files i have to include?

Well, that FAQ entry says to use certain settings that your code does NOT use; so that's something to investigate.

Also, why do you think adding some jar file would solve this? Are you getting ClassNotFound or NoClassDefFound exceptions?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting javax.mail.SendFailedException: Sending failed; Please Help its Urgent
 
Similar Threads
Java mail api
how to configure the mail to send mail in server
urgent help in java mail
AuthenticatedFailedException is thrown javamail
Exception while sending email from a Servlet