Linux 使用sendmail和mutt发邮件问题

我使用sendmail和mutt发送邮件,都无法成功 。这是我找的教程https://www.cnblogs.com/hopewait/p/5198799.html。https://www.cnblogs.com/anovana/p/8107965.html、https://blog.csdn.net/xiongjiezk/article/details/50191515 都会出现连接失败

package com.love.boot.test;

import java.security.GeneralSecurityException;
import java.util.Properties;

import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.sun.mail.util.MailSSLSocketFactory;

public class TestEmail {
public static void main(String[] args) throws MessagingException, GeneralSecurityException {
//登陆邮件客户端
Properties prop = new Properties();
prop.setProperty("mail.host", "smtp.qq.com");
prop.setProperty("mail.transport.protocol", "smtp");
prop.setProperty("mail.smtp.auth", "true");
prop.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
prop.setProperty("mail.smtp.port", "465");
prop.setProperty("mail.smtp.socketFactory.port", "465");
//加密
MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
prop.put("mail.smtp.ssl.enable", "true");
prop.put("mail.smtp.ssl.socketFactory", sf);

    //创建了session会话
    Session session = Session.getDefaultInstance(prop);
    //设置debug模式来调试发送信息
    session.setDebug(true);
    //创建一封邮件对象
    MimeMessage message = new MimeMessage(session);
    //设置主题(标题)
    message.setSubject("欢迎访问我的CSDN博客主页!");
    //正文内容 
    message.setContent("<h1>欢迎访问我的CSDN博客主页</h1>",
            "text/html;charset=utf-8");
    //设置发件人地址
    message.setFrom(new InternetAddress("发送邮箱"));
    //设置多个收信人

    Transport transport = session.getTransport();
    //链接邮件服务器的认证信息
    transport.connect("发送邮箱", "授权码");
    // 设置收件人地址,并发送邮件
    transport.sendMessage(message, new InternetAddress[]{new InternetAddress("接收邮箱")});
    transport.close();
}

}

你先确认一下,linux服务器本机可以发邮件出来吗? 可以用mail命令测试一下 你的博客园的连接打不开了

linux msmtp + mutt + ssl 邮件发送

java 发送邮件工具类,发送html、带附件的均可。