Vous êtes sur la page 1sur 6

Using JavaMail API to send an email in JAVA | Techartifact

http://www.techartifact.com/blogs/2009/08/java-code-to-use-javamail-...

About
Disclaimer

564Subscribers 237Fans 70Followers


Home
Oracle ADF
Java
Spring
.NET
News
Join Us
5

Using JavaMail API to send an email in JAVA


Vinay 06 Aug 2009 API, Email, Java, JavaMail Api Views: 8,347 views
We can send mail through JavaMail Api through java code.I have read somewhere and thought of sharing
with everyone.
For using this code you need to JavaMail Api.
//get mail session
Properties props = new Properties();
props.put("mail.smtp.host","localhost");
Session session = session.getDefaultInstance(props);
// create the messge.
MimeMessage message = new MimeMessage(session);
message.setSubject("Vinay first Mail");
Message.setText("Vinay mail text ");
//address the message
InternetAddress addfrm = new InternetAddress("vinaycen@gmail.com");
message.setFrom(addfrm);
InternetAddress addto = new InternetAddress("vinaycen@yahoo.com");
message.setRecipient(Message.RecipientType.TO,addto);
//send message
Transport.send(message);
Update
Send email in text and html format Text and HTML format
Rate This
0

1 of 6

13-02-2013 16:02

Using JavaMail API to send an email in JAVA | Techartifact

2 of 6

http://www.techartifact.com/blogs/2009/08/java-code-to-use-javamail-...

Vinay
I am software professional, working on Java/J2EE/ADF technologies i.e
Java,J2ee,Oracle ADF,hibernate,J2ee,PL/sql,Apps for 5+ years.I am
passionate about learning new technologies.I am sharing my knowledge. Give
your views and suggestion on vinay[at]techartifact.com
More Posts - Website
Follow Me:

Related Posts
creating a basic skeleton to invoke an AM in Java Class in Oracle ADF
01 Feb 2013
Java program to SORT MAP based on KEYS
08 Jan 2013
Why use hashMap when ConcurrentHashMap is there | Techartifact
12 Dec 2012

5 Responses to Using JavaMail API to send an email in JAVA

1.
Rommel Sharma
Aug 10, 2009
To add to the above not to forget the essentials:
The Java Mail API used here is like a Mail User Agent. In the example above you need the mail
transfer agent that in this example assumes localhost.
Please give your SMTP server address that acts as the MTA, without which it would not work.
Rest looks good.
Cheers,
Rommel.
reply

13-02-2013 16:02

Using JavaMail API to send an email in JAVA | Techartifact

3 of 6

http://www.techartifact.com/blogs/2009/08/java-code-to-use-javamail-...

2.
Ahmad
Aug 19, 2009
What about adding attachments?
reply

3.
waqas ali
Dec 02, 2009
sir, i need help and source code form you about (sending text from pc without using a fax
machine).
reply

Trackbacks/Pingbacks
1. PimpThisBlog.com
2. java send mail in text and html | TechArtifact

Leave a Reply
Name (*)

Email (will not be published) (*)

Website

13-02-2013 16:02

Using JavaMail API to send an email in JAVA | Techartifact

http://www.techartifact.com/blogs/2009/08/java-code-to-use-javamail-...

Web Page Blocked


You have tried to access a web page
which is in violation of your internet
usage policy.
URL:
googleads.g.doubleclick.net/pagead
/ads?client=ca-

Archives

Web Page Blocked

Top Post
Thread Pool in java - 122,281 views
Implementation of thread Pool in java - 44,349 views
Oracle ADF interview Question Part 1 - 40,108 views
Serialization Vs Externalization - 36,453 views
Anonymous Classes in Java - 35,273 views
What is Ext-Js(Extended JavaScript) - 31,741 views
Interview question on thread in Java - 30,427 views
Interface vs Abstract Class - 29,911 views
Marker interface in java - 29,041 views
Hello World Tutorial in ADF - 23,440 views

4 of 6

13-02-2013 16:02

Using JavaMail API to send an email in JAVA | Techartifact

http://www.techartifact.com/blogs/2009/08/java-code-to-use-javamail-...

You have tried to


access a web page
which is in
violation of your
internet usage
policy.
URL:
googleads.g.doubleclick.net/pagead
/ads?client=capub-7884501643823458&
output=html&
h=600&
slotname=2524100578&
w=160&
lmt=1360751155&
flash=11.4.402&
url=http%3A%2F
%2Fwww.techartifact.com%2Fblogs%2F2009
code-touse-javamailapi-tosend-email.html&

Tags

ADF ajax ASP.NET ASP.NET 2.0 C#.NET C#.NET 2.0 code example column Design Pattern
Example extjs features get hashmap hibernate J2EE Java Java design Pattern Javascript Jetspeed2 Jquery
JSF JSF 2.0 lifecycle managed bean Memory method Microsoft Mysql Open Portal Open Source

Oracle ADF portal programmatically row Spring sql server table Task flow Techartifact Tips value
view object Web Development XML

Go To Top
Copyright 2009-2012 Techartifact.com

Web Page Blocked


Disclaimer
About
5 of 6

13-02-2013 16:02

Using JavaMail API to send an email in JAVA | Techartifact

6 of 6

http://www.techartifact.com/blogs/2009/08/java-code-to-use-javamail-...

13-02-2013 16:02

Vous aimerez peut-être aussi