import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
class MailSend {
private static final String EMAIL_OWNER_ADDR_HOST = "smtp.qq.com"; //smtp.163.com smtp.aliyun.com smtp.qq.com
private static final String EMAIL_OWNER_ADDR = "xxxxx@qq.com";
private static final String EMAIL_OWNER_ADDR_PASS = "xxxxxxx";
public static void sendMail(String title, String email, String content) throws MessagingException {
Properties prop = new Properties();
prop.put("mail.host", EMAIL_OWNER_ADDR_HOST);
prop.put("mail.transport.protocol", "smtp");
prop.put("mail.smtp.auth", "true");
prop.setProperty("mail.smtp.ssl.enable", "true");
Session session = Session.getInstance(prop);
Transport ts = session.getTransport();
ts.connect(EMAIL_OWNER_ADDR, EMAIL_OWNER_ADDR_PASS);
MimeMessage mm = new MimeMessage(session);
mm.setFrom(new InternetAddress(EMAIL_OWNER_ADDR));
mm.setRecipient(Message.RecipientType.TO, new InternetAddress(email));
mm.setSubject(title);
mm.setContent(content, "text/html;charset=utf-8");
ts.sendMessage(mm, mm.getAllRecipients());
}
}
邮件发送
最新推荐文章于 2024-05-27 21:44:11 发布