Skip navigation.
Home

Java Mail APIs

__This is an update to Ahmed Hashim's submission__ *Java mail technology *how to use *sample A simple class to hold message information: {{{ public class Email{ public Address[] fromEmail; public Address[] replyTo; public Address[] toEmail; public String subject; public String message; public Date sentDate; public Address[] parse(String address) throws AddressException{ return InternetAddress.parse(address); } } }}} A simple sender method {{{ public static void sendMessage(String smtpServer, Email mail) throws Exception{ Properties myProperties = System.getProperties(); myProperties.put("mail.hashim.com", smtpServer); Session session = Session.getDefaultInstance(myProperties, null); MimeMessage message = new MimeMessage(session); message.addFrom(mail.fromEmail); message.setReplyTo(mail.replyTo); message.addRecipients(Message.RecipientType.TO, mail.toEmail); message.setSubject(mail.subject); message.setText(mail.message); message.setSentDate(mail.sentDate); Transport.send(message); } }}}

Email class or interface ???

{{{ public static void sendMessage(String smtpServer,Email mail) }}} Where did you get the 'Email' class/interface? Knowing that it is not in the Standard Mail API, you should have pointed that out.

This is another class :)

This is another class :) which i didn't add here. -------------%%% __Ahmed Hashim__%%%

It is a simple structure

from the code above, it seemd that Email is a simple structure that has no methods, but it do have String fields (replyTo, Message, etc...) ------------- Amr Kourany Software Engineer

It is true.

It is true. -------------%%% __Ahmed Hashim__%%%

Come on Guys, yes it seems

Come on Guys, yes it seems just like what it looks like :). One should point out that this is not a JavaMail API provided class so readers won't get confused . For example, Amr just got confused claiming those are String fields, while replyTo for example should be an Address[] instance.

Comon hplusplus, add the

Comon hplusplus, add the code man :) create the class and update the page ;) -------------%%% __Ahmed Hashim__%%%