Solved

how to send mail using Javamail with authentication

Posted on 2002-07-12
5
393 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with Pie chart in Jsp 20 223
issue with pdf generation 2 93
HTML5 vs JSP - REST based application development 4 1,208
jdbc error in jsp application 20 63
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 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