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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

How to send a mail ?

 
Greenhorn
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?

Regards
Lohith M.K.
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The http://faq.javaranch.com/java/JavaEnterpriseEditionFaq 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.
 
Greenhorn
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;
try{

Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.host", <your_host> ;
props.put("mail.smtp.host", <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.setFrom(fromAddr);
msg.setSubject(<subject> ;
Multipart mp = new MimeMultipart();

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



Hope this helps!

Sincerly,
Your friends at www.javaadvice.com
www.javaadvice.com - 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)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!