我尝试使用Spring使用SendGrid服务发送电子邮件,但我总是收到此错误:Unauthenticated senders not allowed
。
这是我的java:
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(from);
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
...和我的yml:
mail:
host: smtp.sendgrid.net
username: myusername
password: mypassword
答案 0 :(得分:0)
我明确地告诉发件人必须使用身份验证进行请求,如下所示:
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(from);
message.setSubject(subject);
message.setText(content, isHtml);
Properties mailProperties = new Properties();
mailProperties.put(MAIL_TRANSPORT_PROTOCOL, "smtp");
mailProperties.put(MAIL_SMTP_AUTH, "true");
javaMailSender.setJavaMailProperties(mailProperties);
javaMailSender.send(mimeMessage);