• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
}

}
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
lokesh pattajoshi
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you actually read that FAQ entry and pay attention to the details?
 
lokesh pattajoshi
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try setting the From address.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic