阅读背景:

JavaMail发送邮件中的AuthenticationFailedException异常解决

来源:互联网 

先附上代码

public class JavaMail {
    @Test
    public void func() throws MessagingException {
        Properties prop = new Properties();
        prop.setProperty("mail.host","smtp.163.com");
        prop.setProperty("mail.smtp.auth","true");

        Authenticator aut = new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("yonghuming","mima");//由于涉及隐私就用拼音代替了

            }
        };

        Session session = Session.getInstance(prop,aut);
        MimeMessage msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress("[email protected]"));//sender

        msg.setRecipients(Message.RecipientType.TO,"[email protected]");//recipients
        msg.setSubject("这是一封测试邮件");
        msg.setContent("你猜猜看是啥","text/html;charset=utf-8");
        Transport.send(msg);
    }
public class JavaMail {
    @Test



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: