下面代码中的TO来自于数据库。Properties props = System.getProperties();
if (mailhost != null)
props.put("mail.smtp.host", mailhost); // Get a Session object
Session session = Session.getDefaultInstance(props, null);
// construct the message
Message msg = new MimeMessage(session);
if (from != null)
msg.setFrom(new InternetAddress(from));
else
msg.setFrom(); msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
if (cc != null)
msg.setRecipients(Message.RecipientType.CC,
InternetAddress.parse(cc, false));
if (bcc != null)
msg.setRecipients(Message.RecipientType.BCC,
InternetAddress.parse(bcc, false)); msg.setSubject(subject);
msg.setText("this is the first sample");
msg.setHeader("X-Mailer", mailer);
msg.setSentDate(new Date()); // send the thing off
Transport.send(msg); System.out.println("\nMail was sent successfully.");
if (mailhost != null)
props.put("mail.smtp.host", mailhost); // Get a Session object
Session session = Session.getDefaultInstance(props, null);
// construct the message
Message msg = new MimeMessage(session);
if (from != null)
msg.setFrom(new InternetAddress(from));
else
msg.setFrom(); msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
if (cc != null)
msg.setRecipients(Message.RecipientType.CC,
InternetAddress.parse(cc, false));
if (bcc != null)
msg.setRecipients(Message.RecipientType.BCC,
InternetAddress.parse(bcc, false)); msg.setSubject(subject);
msg.setText("this is the first sample");
msg.setHeader("X-Mailer", mailer);
msg.setSentDate(new Date()); // send the thing off
Transport.send(msg); System.out.println("\nMail was sent successfully.");
解决方案 »
- 请问Hibernate插入数据时返回ID,JPA/EntityManager不返回,有什么好办法获取它么?
- java是否合适应用于电子商务网站开发?
- 关于用户的分类
- [请教高手]请问如何在Java servlet 中使用javascript 得confirm()
- 想用Java技术制作一个中型商务站点,主要是搜索用。请高手指导下思路
- 谁在jsp里面用过序列???急求,那位高手指教???
- 初学者的一个问题:
- 谁会在JSP写浮动图片的代码?
- tomcat通过server.xml文件部署项目不成功
- jsp中数据库连接的问题哈
- JSP在国外的应用情况(在外国或外企或国内知名软件公司工作过的请进)
- 我在使用jbuild8时出现错误,不能保存 com.borland.primetime.util.AssertionException: gbk
是什么意思
cc bcc 又代表是什么?
mail.smtp.host 是你的smtp主机
cc,bcc 去看你的outlook express的帮助
裡面去找!
對你很有幫助!
这里面有非常完整的教程。