java 发送mail
来源:互联网 发布:电脑网络不稳定老掉线 编辑:程序博客网 时间:2024/05/17 04:46
package zh;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class SendMainl ...{
//smtp.sohu.com
private static final String SMTP_HOST = "smtp.163.com";
private static final String SENDER_NAME = "熊猫飞天有限责任公司";
private static final String SENDER_EMAIL_ADDRESS = "mail@163.com";
public void sendConfirmation() ...{
StringBuffer message = new StringBuffer();
message.append("Hello!");
message.append("哈哈!!");
sendMessage("to@163.com", "Sorry!java mail test", message.toString());
}
protected void sendMessage(String recipient, String subject, String message) ...{
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.host", SMTP_HOST);
props.put("mail.smtp.user", "mail@163.com");
props.put("mail.smtp.password", "code");
Session session = Session.getDefaultInstance(props, null);
try ...{
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(SENDER_EMAIL_ADDRESS, SENDER_NAME));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(
recipient));
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(message);
Transport transport = session.getTransport("smtp");
transport.connect((String) props.get("mail.smtp.host"), props
.getProperty("mail.smtp.user"), props
.getProperty("mail.smtp.password"));// 2
transport.sendMessage(msg, msg.getAllRecipients());
} catch (Exception e) ...{
System.out.println(e);
}
}
public static void main(String[] args) ...{
SendMainl sendMail = new SendMainl();
sendMail.sendConfirmation();
}
}
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class SendMainl ...{
//smtp.sohu.com
private static final String SMTP_HOST = "smtp.163.com";
private static final String SENDER_NAME = "熊猫飞天有限责任公司";
private static final String SENDER_EMAIL_ADDRESS = "mail@163.com";
public void sendConfirmation() ...{
StringBuffer message = new StringBuffer();
message.append("Hello!");
message.append("哈哈!!");
sendMessage("to@163.com", "Sorry!java mail test", message.toString());
}
protected void sendMessage(String recipient, String subject, String message) ...{
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.host", SMTP_HOST);
props.put("mail.smtp.user", "mail@163.com");
props.put("mail.smtp.password", "code");
Session session = Session.getDefaultInstance(props, null);
try ...{
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(SENDER_EMAIL_ADDRESS, SENDER_NAME));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(
recipient));
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(message);
Transport transport = session.getTransport("smtp");
transport.connect((String) props.get("mail.smtp.host"), props
.getProperty("mail.smtp.user"), props
.getProperty("mail.smtp.password"));// 2
transport.sendMessage(msg, msg.getAllRecipients());
} catch (Exception e) ...{
System.out.println(e);
}
}
public static void main(String[] args) ...{
SendMainl sendMail = new SendMainl();
sendMail.sendConfirmation();
}
}
- java发送mail
- java发送mail
- java 发送mail
- Java Mail 发送邮件
- JAVA MAIL发送邮件
- java 发送mail
- 发送电子邮件 java mail
- Java Mail 发送邮件
- Java mail发送邮件
- JAVA发送mail
- java mail 发送邮件
- Java Mail发送邮件
- java mail邮件发送
- java mail 发送邮件
- Java mail发送邮件
- java mail发送邮件
- Java mail 发送邮件
- java mail发送邮件
- 听说是世界编程第一名(很简单,你也能实现)
- fjnu 1823 The Worm Turns
- 各种酒英文名
- fjnu 1310 TEX Quotes
- fjnu 1310 TEX Quotes
- java 发送mail
- 逆向工程之内核下创建用户进程
- SOA 新业务语言 新系统架构——参考模型和重要概念
- NTFS和FAT32互相转换
- 恢复SSDT使瑞星保护失效
- fjnu 1543 Ones
- 现在,该你出场(英雄会刊首语)
- fjnu 1892 A Mathematical Curiosity
- 怎么做一个壳 Part