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

类别:Java 点击:0 评论:0 推荐:

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("[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])


DEBUG: SMTPTransport connected to host "202.108.44.210", port: 25


DEBUG SMTP SENT: EHLO lizongbo

DEBUG SMTP RCVD: 250-mx7
250-PIPELINING
250-AUTH LOGIN PLAIN NTLM
250-AUTH=LOGIN PLAIN NTLM
250 8BITMIME


DEBUG SMTP Found extension "PIPELINING", arg ""

DEBUG SMTP Found extension "AUTH", arg "LOGIN PLAIN NTLM"

DEBUG SMTP Found extension "AUTH=LOGIN", arg "PLAIN NTLM"

DEBUG SMTP Found extension "8BITMIME", arg ""

DEBUG SMTP: use8bit false

DEBUG SMTP SENT: MAIL FROM:<[email protected]>

DEBUG SMTP RCVD: 250 Ok


DEBUG SMTP SENT: RCPT TO:<[email protected]>

DEBUG SMTP RCVD: 250 Ok


Verified Addresses

  [email protected]

DEBUG SMTP SENT: DATA

DEBUG SMTP RCVD: 354 End data with <CR><LF>.<CR><LF>


DEBUG SMTP SENT:

.

DEBUG SMTP RCVD: 250 Ok: queued as NkBMWIV9KUKqYBoE.1


DEBUG SMTP SENT: QUIT

本文地址:http://com.8s8s.com/it/it11057.htm