无法使用Spring JavaMail从服务器Heroku发送电子邮件 [英] Cannot send email from server heroku using spring javamail
问题描述
我尝试使用 Spring javamail 从 Heroku 发送电子邮件,但是出现了错误.
I tried to send Email from Heroku, using Spring javamail, but got error.
我的代码:
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service;
@Service("mailService")
public class JavaMailerServiceImpl {
private MailSender mailSender;
public JavaMailerServiceImpl(JavaMailSenderImpl mailSender) {
this.mailSender = mailSender;
}
public void sendMail(String to, String subject, String body){
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(to);
message.setSubject(subject);
message.setText(body);
mailSender.send(message);
}
}
豆类:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com"/>
<property name="port" value="587"/>
<property name="username" value="**********@gmail.com"/>
<property name="password" value="********"/>
<property name="javaMailProperties">
<props>
<prop key="mail.transport.protocol">smtp</prop>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.debug">true</prop>
</props>
</property>
</bean>
和控制器:
@Autowired
private JavaMailerServiceImpl mailService;
@RequestMapping(method = RequestMethod.POST)
public String sendEmail(HttpServletRequest request) {
String recipientAddress = request.getParameter("recipient");
String subject = request.getParameter("subject");
String message = request.getParameter("message");
mailService.sendMail(recipientAddress,subject,message);
}`
在localhost:8080和localhost:5000上,测试成功完成,但是在heroku服务器上,我有例外:
At localhost:8080 and localhost:5000, test completed successfully, but on heroku server I have exception:
身份验证失败;嵌套的异常是javax.mail.AuthenticationFailedException:534-5.7.14请通过Web浏览器和534-5.7.14登录,然后重试. 534-5.7.14进一步了解534 5.7.14 https://support.google.com/mail/answer/78754 j4sm53975482wjg.20-gsmtp
Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 j4sm53975482wjg.20 - gsmtp
我执行了Google的所有建议.您能帮我解决这个问题吗?也许链接或类似的东西.谢谢.
I performed all recommendations from google. Can you help me solve this problem. Maybe link or something like that. Thank you.
推荐答案
Devcenter heroku说:
Devcenter heroku said:
Heroku平台本身不提供电子邮件服务-而是提供充当后备服务的附件-可以附加到您的应用程序中以提供服务.
The Heroku platform itself doesn’t provide an email service - but instead provides add-ons that act as backing services - that can be attached to your app to provide the service.
请咨询Heroku附加组件市场,以获取符合您要求的适当电子邮件服务.
Consult the Heroku Add-ons marketplace for an appropriate email service that matches your requirements.
这篇关于无法使用Spring JavaMail从服务器Heroku发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!