SendOfficeMail
博客专区 > 小白N 的博客 > 博客详情
SendOfficeMail
小白N 发表于4个月前
SendOfficeMail
  • 发表于 4个月前
  • 阅读 0
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

package com.adobe.sunTrust;

import java.util.Date; import java.util.Properties;

import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.NoSuchProviderException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage;   public class SendOfficeMail {       static int port = 587;   //smtp端口     static String server = "smtp.office365.com";   //smtp服务器地址         static String from = "";   //发送者     static String password = "";   //密码     static String user = "";    //发送者地址     public void sendEmail(String email, String subject, String body) {         try {             Properties props = new Properties();             props.put("mail.smtp.host", server);             props.put("mail.smtp.port", String.valueOf(port));             props.put("mail.smtp.auth", "true");             props.put("mail.smtp.starttls.enable", "true");             Transport transport = null;             Session session = Session.getDefaultInstance(props, null);             transport = session.getTransport("smtp");             transport.connect(server, user, password);             MimeMessage msg = new MimeMessage(session);             msg.setSentDate(new Date());             InternetAddress fromAddress = new InternetAddress(from);             msg.setFrom(fromAddress);             InternetAddress[] toAddress = new InternetAddress[1];             toAddress[0] = new InternetAddress(email);             msg.setRecipients(Message.RecipientType.TO, toAddress);             msg.setSubject(subject, "UTF-8");                msg.setText(body, "UTF-8");             msg.saveChanges();             transport.sendMessage(msg, msg.getAllRecipients());             System.out.println("successful");         } catch (NoSuchProviderException e) {             e.printStackTrace();         } catch (MessagingException e) {             e.printStackTrace();         }     }      public static void main(String[] args){          SendOfficeMail sm = new SendOfficeMail();          sm.sendEmail("@qq.com", "asas", "Yanhui Wang has sent you an ad from the SunTrust AdBuilder. Click on the link below to download the ad or copy and paste the link to the address bar of your web browser."+ "\n\n"+""+ "\n\n"+"Thank you for using SunTrust AdBuilder."+ "\n\n"+"Note: This is an auto generated e-mail message. Please do not reply.");      }   }

标签: SendOfficeMail
共有 人打赏支持
粉丝 0
博文 2
码字总数 358
×
小白N
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: