当前位置:编程学习 > JSP >>

用javamail免认证方式发送邮件给163.com的用户的完整代码实例

java代码:
---------------------------------------------------------------------------------------
package com.lizongbo;
import java.util.*;
import javax.mail.internet.*;
import javax.mail.*;
/**
* <p>Title: javamail to 163 </p>
*
* <p>Description: 用javamail免认证方式发送邮件给163.com的用户,
* 具体原理不在此作详细解说,有兴趣者请自行查阅相关资料。
* /p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: lizongbo </p>
*
* @author lizongbo http://www.donews.net/lizongbo
* @version 1.0
*/
public class JavaMail163 {
public static void main(String[] args) throws AddressException,
MessagingException {
Properties mailpro = new Properties();
mailpro.setProperty("mail.smtp.host", "202.108.44.210");
Session session = Session.getDefaultInstance(mailpro);
session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("lizongbo@gmail.com"));
msg.setRecipient(Message.RecipientType.TO,
new InternetAddress("li_zongbo@163.com"));
msg.setSubject("测试免认证方式发送邮件!!!");
msg.setText("测试一下,邮件来自 http://www.donews.net/lizongbo ");
Transport.send(msg);
}
}
---------------------------------------------------------------------------------------
执行结果:
---------------------------------------------------------------------------------------
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG: SMTPTransport trying to connect to host "202.108.44.210", port 25
DEBUG SMTP RCVD: 220 Coremail SMTP(Anti Spam) System (163com[20050206])
补充:Jsp教程,邮件
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,