81,092
社区成员
发帖
与我相关
我的任务
分享
DEBUG: setDebug: JavaMail version 1.4.3
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "pop.sina.com", port 25, isSSL false
发送邮件产生的错误:Could not connect to SMTP host: pop.sina.com, port: 25
public int sendMail(SendMailForm s) {
int ret = 0;
String host = s.getHost(); //POP3服务器
String from = s.getAddresser(); //发件人
String to = s.getAddressee(); //收件人
String subject = s.getTitle(); //主题
String content = s.getContent(); //邮件内容
String password = s.getPwd(); //发件人密码
String path = s.getAdjunct(); //附件1
String path1=s.getAdjunct1(); //附件2
try {
//String mailserver ="smtp."+to.substring(to.indexOf('@')+1,to.length());
//在Internet上发送邮件时的代码
String mailserver =host; //在局域网内发送邮件时的代码
Properties prop = new Properties(); //实例化Properties类
prop.put("mail.smtp.host", mailserver);
//指定采用SMTP协议的邮件发送服务器的主机名
prop.put("mail.smtp.auth", "true"); //指定SMTP服务器需要验证
Session sess = Session.getDefaultInstance(prop);
//根据已经配置的属性创建Session实例
sess.setDebug(true); //设置调试标志
MimeMessage message = new MimeMessage(sess); //实例化MimeMessage类
message.setFrom(new InternetAddress(from)); // 给消息对象设置发件人
//设置收件人
String toArr[]=to.split(",");
//将以逗号分隔的收件人字符串转换为数组
InternetAddress[] to_mail=new InternetAddress[toArr.length];
for(int i=0;i<toArr.length;i++){
to_mail[i]=new InternetAddress(toArr[i]);
//将收件人地址转换为InternetAddress类的对象
}
message.setRecipients(Message.RecipientType.TO,to_mail); //设置收件人
message.setSubject(subject); //设置主题
java.util.Date sendTime=new java.util.Date();
...
}