若依 Springboot框架、
private boolean sendMail(String subject,String content,String receiver) {
String FROM = "public@suztfamdmfg01.jv.tfme.com";
String mail = "Roy.Zhang@tf-amd.com";//收件人
// String smtp = getSmtpByEmail(mail);
// System.out.println(smtp);
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "172.16.2.34");
props.put("mai.smtp.auth", "false");
Session session = Session.getInstance(props, null);
MimeMessage msg = new MimeMessage(session);
try {
msg.setFrom(FROM);
msg.setSubject(subject, "gb2312");
Multipart multipart = new MimeMultipart();
MimeBodyPart bodyPart = new MimeBodyPart();
// bodyPart.setText("�����ʼ�", "gb2312");
bodyPart.setContent(content, "text/html;charset=utf-8");
multipart.addBodyPart(bodyPart);
msg.setContent(multipart);
msg.addHeader("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869");
msg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(mail));
Transport.send(msg);
return true;
} catch (Exception e) {
// e.printStackTrace();
System.out.println(e.getMessage());
return false;
}
}