Solved

how to send mail using Javamail with authentication

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
An article on effective troubleshooting
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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