This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

How to send a mail ?

Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
i am making an application in which i want to send a mail from my Application
to any one in the world.
please help me in solving this?
try to explain me in Steps or get me few sites so that i can go through it?

Lohith M.K.
Posts: 43011
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The has links to several introductory articles and FAQs covering JavaMail, which is the Java API for sending and receiving email.

Since this seems to have nothing to do with Struts, I'll move it to the Other Java APIs forum, where JavaMail is discussed.
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is the code to send mail using Java. Make sure that you know the host/smtp-host name and other parameters.

boolean mailSent = false;

Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("", <your_host> ;
props.put("", <your_smtp_host> ;
Session sess = Session.getDefaultInstance(props);
Message msg = new MimeMessage(sess);

String toAddr =<comma seperated address>;

msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse(toAddr));
String rplAddr = mailProps.getProperty("reply_address");
String fromPerson = mailProps.getProperty("from_personal");

InternetAddress fromAddr = new InternetAddress(<your_reply_address> ;

msg.setSubject(<subject> ;
Multipart mp = new MimeMultipart();

BodyPart pixPart = new MimeBodyPart();
pixPart.setContent(content, "text/html"); //for sending text/html mail
mailSent = true;
}catch(Throwable t){
mailSent = false;
//handle exception
return mailSent;

Hope this helps!

Your friends at - The place where your questions are answered directly.
This guy is skipping without a rope. At least, that's what this tiny ad said:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!