·您的位置: 首页 » 资源教程 » 编程开发 » JAVA、JSP » 发邮件时终于可以通过SINA的SMTP验证了

发邮件时终于可以通过SINA的SMTP验证了

类别: JSP教程  评论数:0 总得分:0
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;


public class sendMail
{
public static void main(String args[]) throws Exception
{

String host = "smtp.sina.com.cn";
String from = "javamail@sina.com";
String to = "javamail@china.com";
String username = "javamail";
String password = "password";

// Get system properties
// Properties props = System.getProperties(); 很多例子中是这样的,其实下面这句更好,可以用在applet中
Properties props = new Properties();

// Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true"); //这样才能通过验证

// Get session
Session session = Session.getDefaultInstance(props);

// watch the mail commands go by to the mail server
session.setDebug(true);

// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");

// Send message
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
}
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1