脚本宝典收集整理的这篇文章主要介绍了邮件发送简单例子-bean文件,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
SimpleSendMessage.java
import java.util.*;
import javax.m
ail.*;
import javax.mail.
internet.*;
import javax.activation.*;
p
ublic class SimpleSendMessage {
public
static void main(String[]
args) {
// Collect the necessary information to send a simple message
// Make sure to replace the values for host, to, and
From w
ITh
// valid information.
// host - must be a valid smtp server t
hat you @R_
777_834@ly have
// access to.
// to - whoever is going to get your email
// f
rom - whoever you want to be. Just remember that many smtp
// servers will validate the domain of the from address
// before allowing the mail to be sent.
String host = "server.myhost
.COM";
String to = "YourFriend@somewhere.com";
String from = "
;meMeMe@myhost.com";
String subject = "JSP Rules!";
String messageText = "I
am sending a message using the"
+ " JavaMail API.\nI can include any text that I want.";
boolean sessionDebug = false;
// Create some
PRo
PErties and get the default Session.
Properties props =
System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
Session session = Session.getDefaultInstance(props, null);
// Set debug on the Session so we can see what is going on
// Passing false will not echo debug info, and passing true
// will.
session.setDebug(sessionDebug);
try {
// Instantiate a new MimeMessage and fill it with the
// requi
red information.
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
// Hand the message to the default transport service
// for delivery.
Transport.send(msg);
}
catch (Messa
gingException mex) {
mex.printStackTrace();
}
}
}
脚本宝典总结
以上是脚本宝典为你收集整理的邮件发送简单例子-bean文件全部内容,希望文章能够帮你解决邮件发送简单例子-bean文件所遇到的问题。
如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。