IntelliJ Java IDE
The moose likes Other JSE/JEE APIs and the fly likes cannot send email through Outlook Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply Bookmark "cannot send email through Outlook" Watch "cannot send email through Outlook" New topic
Author

cannot send email through Outlook

Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 96
I am trying to send an email with javamail and I am not able to.

This is my code...



When I run this...this is my response



But when I try to add this lines to send a message




I get this error..



Can anybody help!!
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18370

The exception shows that it's trying to use "localhost" for sending. That's because, unlike the first piece of code, it uses the SMTP host specified in the Properties you use to get the Session. You probably didn't specify any, so it defaults to local host.

You can solve this two ways:
1) Specify the SMTP host with key "mail.smtp.host". The authentication must be done through keys "mail.smtp.user" and "mail.smtp.pass" or an Authenticator.
2) Get a Transport object as in your first piece of code, then first call saveChanges on the message and then use the Transport's non-static sendMessage method:

Also, you don't send emails through Outlook this way. Outlook is the client written by Microsoft. Their server software is called Exchange.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 96
Rob,
Thank you for the reply. It was very helpful. Ive applied the changes you suggested and unfortunately something else came up, which I am not sure but might me harder to debug!

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

But that is specifically one of the entries in the JavaMail FAQ. I strongly recommend you read this document -- not just the part about your current problem, but all of it. That should give you a better insight into how Internet e-mail works.
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 96
Paul,
I cannot view the link.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

Then your google keywords are "javamail faq". If you can't read the link you get from your web search, then I suggest you go to your network manager and complain.
 
 
subject: cannot send email through Outlook
 
Threads others viewed
Sending mail with authentication to Exchange Server 2007
Sending mail through Java
javax.mail.NoSuchProviderException: smtp
Java Mail Problem
JavaMail not sending emails all the time
developer file tools