本地ubuntu,vps是centOS
到底哪里出了问题呢?
另外,在服务器上用Python编写脚本可以发邮件==! 打包实用工具;
导入javax.mail.*;
导入javax.mail.internet.*;
import java.util.*;
公共类邮件发送器{
public void postmail (字符串接收[ ],字符串subject,字符串文本) {
//set the host SMTP地址
resourcebundlerb=resource bundle.get bundle (' mail );
输入端口=25;
//get系统属性
Properties props=new Properties (;
//setup邮件服务器
props.set property (' mail.SMTP.host ',host );
props.put('mail.SMTP.auth ',' true ' );
props.put('mail.SMTP.port ',port );
//getthedefaultsessionobject.props.put (' mail.SMTP.auth ',' true ' );
会话会话会话=session.getdefaultinstance (props,
new javax.mail.Authenticator () ) )。
protectedpasswordauthenticationgetpasswordauthentication (
resourcebundlerb=resource bundle.get bundle (' mail );
重新命名密码验证(username,password );
}
);
try {
//createadefaultmimemessageobject。
//settherfc 822 ' from ' headerfieldusingthe
//valueoftheinternetaddress.getlocaladdressmethod。
消息. setfrom (newinternetaddress ) from );
//addthegivenaddressestothespecifiedrecipienttype。
for (strings :接收) {
sb.append (' );
sb.append(s;
}
message.set recipients (message.recipient type.to,
message.set recipients (message.recipient type.to,
message.set subject (mime utility.encode text ) subject );
message.setcontent(text,' text/html; charset=utf8 ';
日期=new date (;
message.setsentdate(date;
传输. send (消息;
}catch(exceptione ) {
e .打印堆栈跟踪(;
logdetail.logexception(e
}
}
}