<%@ page
import=" javaxmail, javaxmailinternet, javaxactivation,javautil"
%>
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo</TITLE>
</HEAD>
<BODY>
<%
try{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
sendMailSession = SessiongetInstance(props, null);
propsput("mailsmtphost", "smtpjspinsidercom");
Message newMessage = new MimeMessage(sendMailSession);
newMessagesetFrom(new InternetAddress(requestgetParameter("from")));
newMessagesetRecipient(MessageRecipientTypeTO, new InternetAddress(requestgetParameter("to")));
newMessagesetSubject(requestgetParameter("subject"));
newMessagesetSentDate(new Date());
newMessagesetText(requestgetParameter("text"));
transport = sendMailSessiongetTransport("smtp");
transportsend(newMessage);
%>
<P>Your mail has been sent</P>
<%
}
catch(MessagingException m)
{
outprintln(mtoString());
}
%>
</BODY>
</HTML>这是我以前用的 现在有些需要验证的邮箱可用用不了,用不了的话HI我
package mail;
import javautil;
import javaxmail;
import javaxmailinternet;
public class SendMail{
public static void main(String[] args) {
send("标题","内容");
}
public static void send(String h ,String b ) {
try {
Properties p = new Properties(); //Properties p = SystemgetProperties();
pput("mailsmtpauth", "true");
pput("mailtransportprotocol", "smtp");
pput("mailsmtphost", "smtp139com");
pput("mailsmtpport", "25");
//建立会话
Session session = SessiongetInstance(p);
MimeMessage msg = new MimeMessage(session); //建立信息
msgsetFrom(new InternetAddress("bjyyzx@139com")); //发件人
// msgsetRecipient(MimeMessageRecipientTypeTO,
// new InternetAddress("rewfff@139com zhu_yajun@139com")); //收件人
Address []address=new Address[]{new InternetAddress("bbb@139com"),new InternetAddress("aaa@139com")};
msgsetRecipients(MimeMessageRecipientTypeTO,
address); //收件人
msgsetSentDate(new Date()); // 发送日期
msgsetSubject(h); // 主题
msgsetText(b); //内容
// 邮件服务器进行验证
Transport tran = sessiongetTransport("smtp");
tranconnect("smtp139com", "bluebit_cn", "xiaohao");
// bluebit_cn是用户名,xiaohao是密码
transendMessage(msg, msggetAllRecipients()); // 发送
//Systemoutprintln("邮件发送成功");
} catch (Exception e) {
eprintStackTrace();
}
}}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)