File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes cannot send email through Outlook Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
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: 99
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
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
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: 18570
    
    8

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: 99
Paul,
I cannot view the link.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot send email through Outlook