首页 > 编程知识 正文

java向邮箱发送邮件(内网如何发送邮件)

时间:2023-05-04 07:16:48 阅读:69477 作者:2044

本地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

}

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。