JAVAMAIL
INTRODUCTION:
REQUIREMENT:
JavaMail API:
To perform email functionality we need javamail API. So we can download javamail API from
Download JavaMail API
Eclipse Framework:
To Download Eclipse framework from
Download Eclipse Framework
HOW TO INSTALL:
To extract downloaded javamail API file.
To Install Eclipse
PROCEDURE:
1. Open eclipse
2. File-->Project-->java-->java Project-->Give Project Name.
3. Right Click on project name and select Properties and select java Build Path on the left side. And select Add External JARS on the Right side.And Select
javamail API from where you installed.such as smtp,pop etc..
4. Write a Program Given below
5. Run java program(Right click on the javaprogram and select Run As and run.
6. Finally You Get Answer
Example For Sending Email:
package p1;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class MailSender
{
final String senderEmailID = "Your Email ID For gmail";
final String senderPassword = "password";
final String emailSMTPserver = "smtp.gmail.com";
final String emailServerPort = "465";
String receiverEmailID = null;
String emailSubject = null;
String emailBody = null;
public MailSender(String receiverEmailID, String emailSubject, String emailBody)
{
this.receiverEmailID=receiverEmailID;
this.emailSubject=emailSubject;
this.emailBody=emailBody;
Properties props = new Properties();
props.put("mail.smtp.user",senderEmailID);
props.put("mail.smtp.host", emailSMTPserver);
props.put("mail.smtp.port", emailServerPort);
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
// props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", emailServerPort);
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
SecurityManager security = System.getSecurityManager();
try
{
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
// session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setText(emailBody);
msg.setSubject(emailSubject);
msg.setFrom(new InternetAddress(senderEmailID));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress(receiverEmailID));
Transport.send(msg);
}
catch (Exception mex)
{
mex.printStackTrace();
}
}
public class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(senderEmailID, senderPassword);
}
}
public static void main(String[] args)
{
MailSender mailSender=new MailSender("Receiver Email ID","Email Subjectl","Email Body");
}
}
INTRODUCTION:
To enhance java technology,sun provide javamail API Which can be used to perform email functionalty. Such as sending email and receiving email and forwarding email and repling email and deleting email and sending attachment stc..
REQUIREMENT:
JavaMail API:
To perform email functionality we need javamail API. So we can download javamail API from
Download JavaMail API
Eclipse Framework:
To Download Eclipse framework from
Download Eclipse Framework
HOW TO INSTALL:
To extract downloaded javamail API file.
To Install Eclipse
PROCEDURE:
1. Open eclipse
2. File-->Project-->java-->java Project-->Give Project Name.
3. Right Click on project name and select Properties and select java Build Path on the left side. And select Add External JARS on the Right side.And Select
javamail API from where you installed.such as smtp,pop etc..
4. Write a Program Given below
5. Run java program(Right click on the javaprogram and select Run As and run.
6. Finally You Get Answer
Example For Sending Email:
package p1;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class MailSender
{
final String senderEmailID = "Your Email ID For gmail";
final String senderPassword = "password";
final String emailSMTPserver = "smtp.gmail.com";
final String emailServerPort = "465";
String receiverEmailID = null;
String emailSubject = null;
String emailBody = null;
public MailSender(String receiverEmailID, String emailSubject, String emailBody)
{
this.receiverEmailID=receiverEmailID;
this.emailSubject=emailSubject;
this.emailBody=emailBody;
Properties props = new Properties();
props.put("mail.smtp.user",senderEmailID);
props.put("mail.smtp.host", emailSMTPserver);
props.put("mail.smtp.port", emailServerPort);
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
// props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", emailServerPort);
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
SecurityManager security = System.getSecurityManager();
try
{
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
// session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setText(emailBody);
msg.setSubject(emailSubject);
msg.setFrom(new InternetAddress(senderEmailID));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress(receiverEmailID));
Transport.send(msg);
}
catch (Exception mex)
{
mex.printStackTrace();
}
}
public class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(senderEmailID, senderPassword);
}
}
public static void main(String[] args)
{
MailSender mailSender=new MailSender("Receiver Email ID","Email Subjectl","Email Body");
}
}
10 comments:
Very good Information... Its Working Fine for me..
Great thoughts you got there, believe I may possibly try just some of it throughout my daily life.
rpa Training in Chennai
rpa Training in bangalore
rpa Training in pune
blueprism Training in Chennai
blueprism Training in bangalore
blueprism Training in pune
iot-training-in-chennai
Wonderful article, very useful and well explanation. Your post is extremely incredible. I will refer this to my candidates...
python Training institute in Pune
python Training institute in Chennai
python Training institute in Bangalore
This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
Data Science Training in Indira nagar
Data Science Training in btm layout
Python Training in Kalyan nagar
Data Science training in Indira nagar
Data Science Training in Marathahalli
Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
rpa training in bangalore
best rpa training in bangalore
rpa training in pune | rpa course in bangalore
rpa training in chennai
It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
rpa training in bangalore
best rpa training in bangalore
rpa training in pune | rpa course in bangalore
rpa training in chennai
Just Great great great.. Saw lot of posts to do this but you are the BEST.
Thanks a lot.thnks keep it up guys.
Ai & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me.
oracle training in chennai
oracle training in annanagar
oracle dba training in chennai
oracle dba training in annanagar
ccna training in chennai
ccna training in annanagar
seo training in chennai
seo training in annanagar
You got an extremely helpful website I actually have been here reading for regarding an hour. I’m an initiate and your success is incredibly a lot of a concept on behalf of me.Thanks!!
hardware and networking training in chennai
hardware and networking training in tambaram
xamarin training in chennai
xamarin training in tambaram
ios training in chennai
ios training in tambaram
iot training in chennai
iot training in tambaram
I am really happy with your blog because your article is very unique and powerful for new reader.
hardware and networking training in chennai
hardware and networking training in omr
xamarin training in chennai
xamarin training in omr
ios training in chennai
ios training in omr
iot training in chennai
iot training in omr
Post a Comment