6 Nisan 2012 Cuma
Sending Email With Images in a HTML Table Through Java
Mailinizi html şeklinde tasarlayın ve sonra bu html i message ınıza set edin.
message.setContent(your html);
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class MailSender {
/* */
private Properties props = new Properties();
/* */
private Session session;
/* */
private InternetAddress sdriveMail;
/**
*
*/
public MailSender() {
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("info.sdrive","şifre");
}
});
try {
sdriveMail = new InternetAddress("info.sdrive@gmail.com");
} catch (AddressException e) {
}
}
/**
*
* @param mailAddress
* @param userName
* @param nickName
*/
public void sendWelcomeMail(String mailAddress, String userName, String nickName){
try {
Message message = new MimeMessage(session);
message.setFrom(sdriveMail);
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(mailAddress));
message.setSubject("Welcome to SDrive!");
message.setContent
("<html><body><table border = \"3\" width = \"800\"><tr align=\"center\"><td><img src=\"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQRh7AYO4dETB_gzAhFuqyFhFYapzZ7trft3bb9TZCThbLG0lIjrOJXhz6j5EXshqMBbK1NkYQTeY7MAj6yFpOfZWaBq7iJg9XbaxY3KdBJnRsDi3PXamWhWxqt8PqtMtfiwpwMrZYdZfd/s320/t2.png\">"
+ "</td></tr><tr><td height = \"100\" ><h3>Dear Sdrive user,</h3>" + "Welcome to SDrive!" +
" Thank you for registering with Sdrive!</td></tr><tr><td height = \"150\">" +
"<p>Your account information:</p>" +
"<p>Name: " + userName +
"</p><p>User Name: "+ nickName +
"</p><p>Email: "+ mailAddress + "</p><br /><br /><p>Copyright © 2012 SDrive. All rights reserved.</p></td></tr></table></body></html>",
"text/html");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
}
}
public static void main(String[] args) {
MailSender mail = new MailSender();
mail.sendWelcomeMail("baharcglr@gmail.com", "Bahar Çaglar", "baharcaglar");
}
}
Hiç yorum yok:
Yorum Gönder