package com.gotobus.util.email;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import com.sun.mail.smtp.SMTPAddressFailedException;
public class SendMail {
/**
* @param args
*/
public static void main(String[] args) {
String host = "mail.gotobus.com"; //发件人使用发邮件的电子信箱服务器
String from = "no-reply@gotobus.com"; //发邮件的出发地(发件人的信箱)
String to = "wushu201404@gmail.com"; //发邮件的目的地(收件人信箱)
// String to="mark@gotobus.com";
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "false"); //这样才能通过验证
props.put("mail.transport.protocol", "POP3");
props.put("mail.smtp.port", "25");
// MyAuthenticator myauth = new MyAuthenticator();
Session session = Session.getDefaultInstance(props, null);
// Session session = Session.getInstance(props);
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("测试程序--no-reply--!");
message.setText("这是用java写的发送电子邮件的测试程序99999wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwa!");
message.saveChanges();
try {
Transport.send(message);
} catch (SMTPAddressFailedException e) {
throw new SendFailedException("Unable to send to " + to, e);
}
System.out.println("=======success=====");
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
----具体情况描述--------
这个案例是用javamail实现不需要校验身份信息实现邮件发送的功能,目前自己所用的是企业内部邮箱,代码可以实现的是给内部邮箱发件。但换成qq.163.gmail等邮件时,出现了上面的报错。。。。。。但使用perl语言时可以顺利转发,所以,邮箱账户应该不存在问题,求助大神诊断!!!!!!!!!!!!感激不尽!!