SimpleEmail email = new SimpleEmail();
email.setHostName("SMTP服务器");
email.setAuthentication("用户名","密码");
email.addTo("收件人", "收件人名字");
email.setFrom("发件人邮件", "发件人名字");
email.setSubject("Test message");
email.setMsg("This is a simple test of commons-email");
email.send();
2。发送带附件的邮件
EmailAttachment attachment = new EmailAttachment();
attachment.setPath("D:\\123.jpg");
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription(MimeUtility.encodeWord("附件","UTF-8",null));
attachment.setName(MimeUtility.encodeWord("李翔李总管","UTF-8",null));
// Create the email message
MultiPartEmail email = new MultiPartEmail();
email.setHostName("SMTP服务器");
email.setAuthentication("用户名","密码");
email.addTo("jdoe@somewhere.org", "John Doe");
email.setFrom("me@apache.org", "Me");
email.setSubject("The picture");
email.setMsg("Here is the picture you wanted");