最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
用javamail免认证方式发送邮件给163.com的用户的完整代码实例
时间:2022-07-02 18:11:40 编辑:袖梨 来源:一聚教程网
java代码:
---------------------------------------------------------------------------------------
package com.lizongbo;
import java.util.*;
import javax.mail.internet.*;
import javax.mail.*;
/**
*
*
*
*
*
*
* @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("[email protected]"));
msg.setRecipient(Message.RecipientType.TO,
new InternetAddress("[email protected]"));
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])
---------------------------------------------------------------------------------------
package com.lizongbo;
import java.util.*;
import javax.mail.internet.*;
import javax.mail.*;
/**
*
Title: javamail to 163
*
*
Description: 用javamail免认证方式发送邮件给163.com的用户,
* 具体原理不在此作详细解说,有兴趣者请自行查阅相关资料。
* /p>
*
*
Copyright: Copyright (c) 2005
*
*
Company: lizongbo
*
* @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("[email protected]"));
msg.setRecipient(Message.RecipientType.TO,
new InternetAddress("[email protected]"));
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])