java傳送郵件
<span style="white-space:pre"> </span>@Test
public void fun() throws AddressException, MessagingException {
Properties props = new Properties();
props.setProperty("mail.host", "smtp.163.com");
props.setProperty("mail.smtp.auth", "true");
//發件郵箱驗證
Authenticator auth = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("qq83986976", "3854928");
}
};
//得到session
Session session = Session.getInstance(props, auth);
//建立MimeMessage
MimeMessage msg = new MimeMessage(session);
//設定發件人
msg.setFrom(new InternetAddress("qq83986976@163.com"));
/*
* 設定收件人
* to收件人
* cc抄送
* bcc暗送
*/
msg.setRecipients(RecipientType.TO, "83986976@qq.com");
msg.setSubject("測試郵件");
msg.setContent("郵件測試", "text/html;charset=utf-8");
Transport.send(msg);
}
傳送帶有附件的郵件
public void fun2() throws AddressException, MessagingException, IOException {
Properties props = new Properties();
props.setProperty("mail.host", "smtp.163.com");
props.setProperty("mail.smtp.auth", "true");
Authenticator auth = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("qq83986976", "3854928");
}
};
//得到session
Session session = Session.getInstance(props, auth);
//建立MimeMessage
MimeMessage msg = new MimeMessage(session);
//設定發件人
msg.setFrom(new InternetAddress("qq83986976@163.com"));
msg.setRecipients(RecipientType.TO, "83986976@qq.com");
msg.setSubject("我的附件測試");
/*
* 傳送附件,
* 1多部件的部件內容,MimeMultipart
* 2個主體
*/
MimeMultipart list = new MimeMultipart();
//建立MimeBodyPart
MimeBodyPart part1 = new MimeBodyPart();
part1.setContent("附件郵件","text/html;charset=utf-8");
//新增部分
list.addBodyPart(part1);
MimeBodyPart part2 = new MimeBodyPart();
part2.attachFile(new File("F:/黨員.png"));
//顯示在附件上,並處理亂碼
part2.setFileName(MimeUtility.encodeText("黨員.png"));
list.addBodyPart(part2);
msg.setContent(list);
Transport.send(msg);
}
相關文章
- java郵件傳送Java
- Java Mail 郵件傳送(二):簡單封裝的郵件傳送JavaAI封裝
- Java傳送郵件初窺Java
- Java郵件傳送帶附件Java
- 郵件傳送
- 傳送郵件
- Java實現QQ郵件傳送郵件工具類Java
- java 傳送郵件Commons MailJavaAI
- SpringBoot整合Mail傳送郵件&傳送模板郵件Spring BootAI
- Laravel 傳送郵件Laravel
- PHP傳送郵件PHP
- Django——郵件傳送Django
- Laravel傳送郵件Laravel
- gmail傳送郵件AI
- Oracle郵件傳送Oracle
- Powershell郵件傳送
- thinkphp 郵件傳送PHP
- centos 傳送郵件CentOS
- phpcms傳送郵件PHP
- 郵件的傳送
- golang傳送郵件(qq郵箱)Golang
- 郵件傳送API整理API
- php windows 傳送郵件PHPWindows
- 定時傳送郵件
- thinkjs 傳送郵件JS
- 使用phpmailer傳送郵件PHPAI
- Ubuntu的郵件傳送Ubuntu
- python傳送郵件Python
- nodejs 傳送郵件NodeJS
- 傳送郵件那些事
- javamail郵件傳送例子JavaAI
- 使用JavaMail傳送郵件JavaAI
- 使用nodemailer傳送郵件AI
- javamail傳送郵件(轉)JavaAI
- Java Mail 郵件傳送(一):入門DemoJavaAI
- JavaMail:java使用QQ郵箱傳送郵件簡單版。JavaAI
- 使用python傳送郵件和接收郵件Python
- 如何傳送電子郵件到別人郵箱?電子郵件傳送的方法