jmail 553 exception

javax.mail.MessagingException: 553 authentication is required,smtp1,


Properties props = new Properties();
        props.put("mail.smtp.host", ""); //smtp服务器地址

        props.put("mail.smtp.auth", "true");  //是否需要认证

        MyAuthenticator  myauth = new MyAuthenticator ("","");
        //获得一个带有authenticator的session实例
        Session session = Session.getInstance(props,myauth);
        session.setDebug(true);//打开debug模式,会打印发送细节到console
        Message message = new MimeMessage(session); //实例化一个MimeMessage集成自abstract Message 。参数为session
        try
        {
            message.setFrom(new InternetAddress("")); //设置发出方,使用setXXX设置单用户,使用addXXX添加InternetAddress[]

            message.setText("只是一个简简单单的文本内容哟!"); //设置文本内容 单一文本使用setText,Multipart复杂对象使用setContent

            message.setSubject("只是简简单单的文本标题哟!"); //设置标题

            message.setRecipient(Message.RecipientType.TO, new InternetAddress("")); //设置接收方

            Transport.send(message); //使用Transport静态方法发送邮件

        }catch(AddressException e)
        {
            //此处处理AddressException异常  [The exception thrown when a wrongly formatted address is encountered.]

        }catch(MessagingException e)
        {
            //此处处理MessagingException异常 [The base class for all exceptions thrown by the Messaging classes ]
        }


public class MyAuthenticator extends Authenticator {

    private String userName;
    private String password;

    public MyAuthenticator(String userName, String password) {
        this.userName = userName;
        this.password = password;
    }

    protected PasswordAuthentication getPasswordAuthentication(){
           return new PasswordAuthentication(userName,password);
     }
}


有一个帖子让我幌然大悟.


props.put("mail.smtp.auth", "true");  //是否需要认证


上面这句,一般时候,你可能会直接props.put("mail.smtp.auth", true);   注意 ,true加上引号

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值