请问一下,我用javamail发邮件连续发了两封邮件,为什么只有第一封邮件收到啊? 请问一下,我用javamail发邮件连续发了两封邮件,为什么只有第一封邮件收到啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.util.Properties;import javax.mail.*;import javax.mail.internet.AddressException;import javax.mail.internet.MimeBodyPart;import javax.mail.internet.MimeMessage;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMultipart;import java.util.Date;public class SendMail { private Session sendMailSession = null; private String mailtype = "text/html;charset=GBK"; public void sendMail(String mailContent) { getSession(); Message newMessage = new MimeMessage(sendMailSession); try { newMessage.setFrom(new InternetAddress("[email protected]")); InternetAddress[] to = new InternetAddress[1]; to[0] = new InternetAddress("[email protected]"); // 接收方邮件地址 newMessage.setRecipients(Message.RecipientType.TO, to); // 接收方邮件地址 String subject = "加盟商户"; newMessage.setSubject(subject); // newMessage.setText(mailContent); // 邮件正文 不支持html Multipart mp = new MimeMultipart(); // Multipart对象,邮件内容,标题,附件等内容均添加到其中后再生成MimeMessage对象 MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setContent(mailContent, mailtype); mp.addBodyPart(mbp1); newMessage.setContent(mp);// 设置内容 newMessage.setSentDate(new Date(System.currentTimeMillis())); Transport.send(newMessage); } catch (AddressException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } catch (MessagingException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } } /** * 获得一个会话 * * @return */ public Session getSession() { if (sendMailSession == null) { Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.host", "smtp.sina.com"); // smtp主机名。 props.put("mail.smtp.user", "zhcw_jiameng"); // smtp主机名。 props.put("mail.smtp.port", "25"); props.put("mail.smtp.password", "**********"); // 邮件密码。 PopupAuthenticator popA = new PopupAuthenticator(); // 邮件安全认证。 popA.performCheck("zhcw_jiameng", "**********"); // 填写用户名及密码 sendMailSession = Session.getInstance(props, popA); sendMailSession.setDebug(false); } return sendMailSession; }} 关于正则表达式的意思 哪位大哥知道浏览器如何处理和显示服务器传回的HTML代码的? 出现jdbc问题 程序一直找不到JDBC连接SQLServer的类 :( √高手啊,请问如何将BufferedImage转换为可以用SOCKET传输的数据? SCJP考试原题 java and oracle 的联姻 不能编译程序 打印问题 java多态测试小程序问题求解 窗口资源释放的相关问题 怎么在JSP页之间用request对象传递java.util.Properties对象?
import javax.mail.internet.AddressException;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMultipart;import java.util.Date;public class SendMail { private Session sendMailSession = null; private String mailtype = "text/html;charset=GBK"; public void sendMail(String mailContent) {
getSession(); Message newMessage = new MimeMessage(sendMailSession);
try {
newMessage.setFrom(new InternetAddress("[email protected]")); InternetAddress[] to = new InternetAddress[1];
to[0] = new InternetAddress("[email protected]"); // 接收方邮件地址 newMessage.setRecipients(Message.RecipientType.TO, to); // 接收方邮件地址 String subject = "加盟商户";
newMessage.setSubject(subject); // newMessage.setText(mailContent); // 邮件正文 不支持html Multipart mp = new MimeMultipart(); // Multipart对象,邮件内容,标题,附件等内容均添加到其中后再生成MimeMessage对象
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(mailContent, mailtype);
mp.addBodyPart(mbp1);
newMessage.setContent(mp);// 设置内容
newMessage.setSentDate(new Date(System.currentTimeMillis())); Transport.send(newMessage); } catch (AddressException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (MessagingException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} } /**
* 获得一个会话
*
* @return
*/
public Session getSession() {
if (sendMailSession == null) {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.sina.com"); // smtp主机名。
props.put("mail.smtp.user", "zhcw_jiameng"); // smtp主机名。
props.put("mail.smtp.port", "25");
props.put("mail.smtp.password", "**********"); // 邮件密码。
PopupAuthenticator popA = new PopupAuthenticator(); // 邮件安全认证。
popA.performCheck("zhcw_jiameng", "**********"); // 填写用户名及密码
sendMailSession = Session.getInstance(props, popA);
sendMailSession.setDebug(false);
}
return sendMailSession;
}}