springbootメール送信
解決したいこと
springbootでメール送信機能(Gmailの場合)を実装しようとしているのですが、エラーが発生しており、送信ができませんので原因と解決法を教えてください。発生場所は該当するソースコードのsendメソッド内です。
発生している問題・エラー(エラー発生時の変数eの中身)
org.springframework.mail.MailSendException: Failed messages: org.eclipse.angus.mail.smtp.SMTPSendFailedException: 555-5.5.2 Syntax error, cannot decode response. For more information, go to
555-5.5.2 https://support.google.com/a/answer/3221692 and review RFC 5321
555 5.5.2 specifications. u5-20020a056a00098500b006d9bf35dd1fsm17539107pfg.142 - gsmtp
; message exceptions (1) are:
Failed message 1: org.eclipse.angus.mail.smtp.SMTPSendFailedException: 555-5.5.2 Syntax error, cannot decode response. For more information, go to
555-5.5.2 https://support.google.com/a/answer/3221692 and review RFC 5321
555 5.5.2 specifications. u5-20020a056a00098500b006d9bf35dd1fsm17539107pfg.142 - gsmtp
該当するソースコード
MailSendServiceImplクラス
@Service
@RequiredArgsConstructor
public class MailSendServiceImpl implements MailSendService {
/** メール送信用クラス */
private final MailSender mailSender;
@Override
public boolean sendMail(String mailTo, String mailSubject, String mailText) {
var smm = new SimpleMailMessage();
smm.setTo(mailTo);
smm.setSubject(mailSubject);
smm.setText(mailText);
try {
mailSender.send(smm);
} catch (Exception e) {
return false;
}
return true;
}
}
application.properties(メール送信に関わる箇所)
#メール送信機能
#SMTPサーバのホストアドレス
spring.mail.host=smtp.gmail.com
#SMTPサーバのポート番号
spring.mail.port=587
#メールアドレス
spring.mail.username=zhongxiyoufu563@gmail.com
#SMTPサーバのパスワード
spring.mail.password=akmnbxphnooslmhj
#SMTPサーバの認証有無
spring.mail.properties.mail.smtp.auth=true
#暗号化された通信の有無
spring.mail.properties.mail.smtp.starttls.enable=true
build.gradle(メール送信に関わる箇所)
implementation 'org.springframework.boot:spring-boot-starter-mail'
自分で試したこと
application.propertiesの方に原因があると思い、アプリパスワードの方を別で新しく作成したり、そのパスワードを発行時のままコピーして使用(例:akmn bxph noos lmhj)したりしましたが、結果は変わりませんでしたので、恐らく外部のライブラリの可能性があると思うのですが、そちらはまだ試していません。
0 likes