📄 sendmail.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: SendMail.java
package com.cwc.util;
import com.cwc.exception.SendMailException;
import com.cwc.initconf.ConfigBean;
import java.util.Date;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
// Referenced classes of package com.cwc.util:
// SmtpAuthenticator
public class SendMail
{
String smtp;
String user;
String pwd;
public SendMail()
{
smtp = ConfigBean.getStringValue("sendMailSmtp");
user = ConfigBean.getStringValue("sendMailAccount");
pwd = ConfigBean.getStringValue("sendMailPwd");
}
public void send(String from, String to, String subject, String body)
throws SendMailException
{
try
{
Properties props = new Properties();
props.put("mail.smtp.host", smtp);
props.put("mail.smtp.auth", "true");
SmtpAuthenticator sa = new SmtpAuthenticator(user, pwd);
Session sendMailSession = Session.getInstance(props, sa);
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(from));
newMessage.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
newMessage.setSubject(subject);
newMessage.setSentDate(new Date());
newMessage.setContent(body, "text/html;charset=utf-8");
Transport transport = sendMailSession.getTransport("smtp");
Transport.send(newMessage);
}
catch(MessagingException m)
{
throw new SendMailException("SendMail.send() error:" + m);
}
catch(Exception m)
{
throw new SendMailException("systemConfig error");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -