Solved

how to send mail using Javamail with authentication

Posted on 2002-07-12
5
385 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
  • 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 200 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the fileā€¦
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now