java往新浪和163中发送邮件问题。
来源:百度知道 编辑:UC知道 时间:2024/06/08 01:16:57
如果谁有可以发送的源码 发我一份 定当重谢。liufangmeng@163.com
public void send(String to,String links) throws AddressException, MessagingException {
String host="SMTP.SOHU.COM";
String all ="请复制此链接到您的浏览器后,重新设置您的密码";
Properties prop =new Properties();
prop.put("mail.transport.default","smtp");
prop.put("mail.smtp.host",host );
Session mySession=Session.getInstance(prop,null);
Message msg =new MimeMessage(mySession);
msg.setFrom(new InternetAddress("hn@all.com"));
InternetAddress[] address ={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("您的密码");
msg.setSentDate(new Date());
msg.setText(all+":"+links);
Transport.send(msg);
我只想往163里发邮件。
试了一下,确实如楼主所说
研究一下
以下代码通过测试,不知道你收到没有,我给自己发收到了,因为163邮件需要安全认证,如果是outlook配置时,要把安全认证的选项选上,在代码中就是
props.put("mail.smtp.auth", "true");
然后是163许可的用户.
将代码中的user,pass换成你在163注册的用户就可以了
package org.info.mail;
import java.util.Date;
import java.util.Properties;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
/**
* @param args
*/
public static void main(String[] args) {
try {
execute();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public static void execute() throws Exception {
Properties props = System.getProperties();
props.put("mail.smtp.host", "smtp.163.com");
props.put("mail.smtp.auth", "