`
myway84
  • 浏览: 200658 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
文章分类
社区版块
存档分类
最新评论

java发邮件

阅读更多
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();
		}
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics