?
Solved

how to send mail using Javamail with authentication

Posted on 2002-07-12
5
Medium Priority
?
399 Views
Last Modified: 2010-08-05
hi

I already used javamail program to send mail thro' browser on one server. But now when I used the same program on other server it's not worked. when I asked to
my host he said his SMTP is authenticated. he said i have to enter into their smtpserver by providing username and password(using program) and then sent mail to others.

Let me know how to do this.

epdass
0
Comment
Question by:epdass
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 7149241
Use this:

transport.connect(
  host, username, password);

and you MIGHT have to enable auth:
props.put("mail.smtp.auth", "true");

HTH,
CJ
0
 

Author Comment

by:epdass
ID: 7153731
hi

it's also not working. i got exception like authentication failed even the details i have given are correct.

epdass
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 800 total points
ID: 7154660
Did you make sure you set:
props.put("mail.smtp.auth", "true");

and then tried to connect using the hostname, username and password?

If that didn't work then you may have to set up an authenticator:

class SMTPAuthenticator extends Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username="userid";
String password="passwd";
return new PasswordAuthentication(username, password);
}
}

Then you pass the authenticator to your Session as follows:

//Setup authenticator
Authenticator auth = new SMTPAuthenticator();
// Get session
Session session = Session.getDefaultInstance(props, auth);
props.put("mail.smtp.auth", "true");
Transport trans = null;
MimeMessage msg = new MimeMessage(session);
trans = session.getTransport(address);
msg.setFrom(new InternetAddress(fromAdress));
......


Also make sure you are using JavaMail 1.2 or later.

CJ
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 9560838
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

"Accept cheekycj's comment as answer."
 
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Kuldeepchaturvedi
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Check out the latest tech news, community articles, and expert highlights in August's newsletter.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question