Solved

how to send mail using Javamail with authentication

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
communication with a non technical owner 16 100
some methods private some are not 8 196
oracle fusion vs MQ 2 107
JavaScript parse form with colon separated values 2 73
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

912 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

22 Experts available now in Live!

Get 1:1 Help Now