错不过的你.
2021-05-31 15:13
采纳率: 100%
浏览 57
已采纳

使用javamail发送邮件为何邮件是无主题?

使用javamail发送无主题,附上邮件原文

Received: from DESKTOP-0AVLR3N ([119.123.164.68])
	by newxmesmtplogicsvrszb6.qq.com (NewEsmtp) with SMTP
	id A9B358D2; Mon, 31 May 2021 14:42:27 +0800
X-QQ-mid: xmsmtpt1622443347tvck6yw8a
Message-ID: <tencent_39C51FB25CD3419DC2A5B1ABE086896F9E09@qq.com>
X-QQ-XMAILINFO: M+kJ3+asFsV8ptZUg9M5141ZTVUxpCoBaq6GrZ5cQA+c8/T9FhKoDAKmpQ0nXB
	 F5bahk21CsAE4S2pH5aMCdmiQRWSNIMinV16aeI1mHF1VOORmZ6VN1F9LNltlNYfzSFIrTBA3wYj
	 sCf1WBS4OP8eHL+6PF0TKgyzai9cscl0VMiop13zLRgeKzSiU23Rz8wV+/JBabc8oPHtHSZeN+cZ
	 Kg5eP8vBg9P2/q4aUVDf74KTlXk0QuYOu8t+b9EMtJaRdAY1GCW+ru8YpiDztZAWQN2zBBWuVOxn
	 caHTdkp1x6UY/jGgZpVLtJ4D/xzL9XOCwoKXzADrE4ZxCtvDriYGI2D/srIlKCQiW7D99cAKZFjX
	 VyNnignDNSV+XGXCPAEoNqly8v3TCXYGiSFkoF1PxyA09MxUmLvn/aLm8eB6uMHMXlisE1KEx5ym
	 w+hPjINuVg7rJirdogJZQTi6I1s8U4PnOVLio+4qg0Iw2h5HEpuJcd/pMSXl0CzqIe+OgJRnd2c8
	 SXw+ob5rKkOkfDnmlkZRvqZsSRtQJl+oUI6c8EhT1Hbf4PtU5y4zXc88Oh3aS0f5QaDLBSFfFOnL
	 4E3RTBJNy+5clQkaYHDY25VCXwN9ytMNC3zII=
From: xxxx@qq.com
To: xxxx@qq.com
X-OQ-MSGID: <108979786.01622443346666.JavaMail.

后台输出的内容是:

DATA
354 End data with <CR><LF>.<CR><LF>.
From: xxxx@qq.com
To: xxxxx@qq.com
Message-ID: <375562226.01622445154053.JavaMail. �獛澠@smtp.qq.com>
Subject: =?GBK?B?u7bTrdeisuF0aGhoo6E=?=
MIME-Version: 1.0
Content-Type: text/html;charset=UTF-8
Content-Transfer-Encoding: base64

PHA+PGgyPuaBreWWnOazqOWGjOaIkOWKn++8gTwvaDI+PC9wPuaCqOeahOeUqOaIt+WQjeS4uu+8
mjxoND5hPC9oND7or7flpqXlloTkv53nrqHmgqjnmoTlr4bnoIHvvIzlpoLmnInpl67popjor7fl
j4rml7bogZTns7vnvZHnq5nlrqLmnI3vvIzlho3mrKHmrKLov47mgqjnmoTliqDlhaXvvIHvvIE=
.
250 OK: queued as.
QUIT
221 Bye.

哪位大佬帮我看看

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • CSDN专家-sinjack 2021-05-31 15:20
    已采纳

    你把代码发出来,有设置主题的方法。

    已采纳该答案
    打赏 评论
  • weixin_45411740 2021-05-31 15:20
     public boolean sendMail(String to, String text, String title) {
            try {
                final Properties props = new Properties();
                props.put("mail.smtp.auth", "true");
                props.put("mail.smtp.host", "smtp.qq.com");
    
                // 发件人的账号
                props.put("mail.user", user);
                //发件人的密码
                props.put("mail.password", password);
    
                // 构建授权信息,用于进行SMTP进行身份验证
                Authenticator authenticator = new Authenticator() {
                    @Override
                    protected PasswordAuthentication getPasswordAuthentication() {
                        // 用户名、密码
                        String userName = props.getProperty("mail.user");
                        String password = props.getProperty("mail.password");
                        return new PasswordAuthentication(userName, password);
                    }
                };
                // 使用环境属性和授权信息,创建邮件会话
                Session mailSession = Session.getInstance(props, authenticator);
                // 创建邮件消息
                MimeMessage message = new MimeMessage(mailSession);
                // 设置发件人
                String username = props.getProperty("mail.user");
                InternetAddress form = new InternetAddress(username);
                message.setFrom(form);
    
                // 设置收件人
                InternetAddress toAddress = new InternetAddress(to);
                message.setRecipient(Message.RecipientType.TO, toAddress);
    
                // 设置邮件标题
                message.setSubject(title);
    
                // 设置邮件的内容体
                message.setContent(text, "text/html;charset=UTF-8");
                // 发送邮件
                Transport.send(message);
                return true;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return false;
        }
    
        @Test
        public void test() {
            sendMail("要发送的邮箱", "邮件内容", "标题");
    
        }
    
    }
    打赏 评论
  • 有问必答小助手 2021-05-31 16:29

    您的问题已经有小伙伴解答了,请点击【采纳】按钮,采纳帮您提供解决思路的答案,给回答的人一些鼓励哦~~

    ps:开通问答VIP,享受5次/月 有问必答服务,了解详情↓↓↓

    【电脑端】戳>>>  https://vip.csdn.net/askvip?utm_source=1146287632
    【APP 】  戳>>>  https://mall.csdn.net/item/52471?utm_source=1146287632

    打赏 评论

相关推荐 更多相似问题