Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import javax.mail.internet.MimeMessage.RecipientType;
- import org.apache.commons.io.IOUtils;
- import org.codemonkey.simplejavamail.Email;
- import org.codemonkey.simplejavamail.Mailer;
- import org.codemonkey.simplejavamail.TransportStrategy;
- public class MyMailer {
- /**
- * @param args
- * @throws IOException
- * @throws FileNotFoundException
- */
- public static void main(String[] args) throws FileNotFoundException, IOException
- {
- final Email email = new Email();
- email.setFromAddress("Rakesh Waghela", "sender@gmail.com");
- email.setSubject("Hey testing Mail !");
- email.addRecipient("Java India" , "recipient@gmail.com" , RecipientType.TO);
- email.addRecipient("Sony Ujjwal", "anotheremail@gmail.com" , RecipientType.CC);
- email.setText("We should Meet up! ;)");
- email.setTextHTML("<b>We should meet up for..!</b>" +
- "<br/>" +
- "<ol><li>Coffee</li><li>Milk</li></ol> ");
- email.addEmbeddedImage("TestFile.jpg", IOUtils.toByteArray( new FileInputStream(new File("C://image.jpg"))), "image/jpeg");
- new Mailer("smtp.gmail.com", 25, "myuserid@gmail.com", "mypassword",TransportStrategy.SMTP_TLS).sendMail(email);
- }
- }
Add Comment
Please, Sign In to add comment