import java.util.Properties;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
//当接收到告警邮件需要转发时调用此方法
public class SendMail {
public static void send(String title,String trapInfo) throws Exception {
if (trapInfo!=null) {
String text = trapInfo + "\r\n"
+ "RMC Server address: http://10.27.65.115" + "\r\n"
+ "RMC support mailbox: public RMC/rd/employee/hwst";
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.class",
"com.sun.mail.smtp.SMTPTransport");
Session session = Session.getInstance(props);
Transport transport = session.getTransport();
//transport.connect("smtp.huaweisymantec.com", 25, "pub00136",
//"Huawei123");
//服务器IP 端口 账户 ,密码
transport.connect("129.81.1.10", 25, "receive",
"123456");
Message msg = new MimeMessage(session);
//设置标题
msg.setSubject(title);
//设置内容
msg.setText(text);
msg.setFrom(new InternetAddress(
"RMC@notesmail.huaweisymantec.com"));
msg.setReplyTo(InternetAddress
.parse("RMC@notesmail.huaweisymantec.com"));
transport.sendMessage(msg,
new Address[] { new InternetAddress("duanzhenhua@callhome.mail") });
System.out.println("邮件发送成功");
transport.close();
}
}
public static void main(String[] arg)
{
try {
new SendMail().send("Alarm Notice! Source: 2102315382Z083000022","fadfadsfasfadsfad");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
发送邮件的实现
最新推荐文章于 2022-03-12 22:19:10 发布