[英]Why can't I send an email message?
I am faced with the fact that I can not send an email message. 我面对这样的事实,我无法发送电子邮件。 I can not understand the reason. 我不明白原因。 I use Spting Boot 2. The example uses the JavaMailSender class. 我使用Spting Boot2。该示例使用JavaMailSender类。 But you can do without its implementation and the necessary parameters to be specified in the application.properties? 但是,您可以不执行它,而不必在application.properties中指定必需的参数吗?
@Configuration
public class MainConfiguration {
@Bean
public JavaMailSender getJavaMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("smtp.yandex.ru");
mailSender.setPort(465);
mailSender.setUsername("test@yandex.ru");
mailSender.setPassword("test122223");
Properties props = mailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
//props.put("mail.smtp.timeout", 1000);
return mailSender;
}
@Bean
public SimpleMailMessage templateSimpleMessage() {
SimpleMailMessage message = new SimpleMailMessage();
message.setText("This is the test email template for your email:");
return message;
}
}
And after 2 min, i'm have it's error: "javax.mail.MessagingException: Could not connect to SMTP host"
2分钟后,我收到了错误消息: "javax.mail.MessagingException: Could not connect to SMTP host"
Try to add 尝试添加
spring.mail.properties.mail.smtp.ssl.enable=true
or 要么
props.put("mail.smtp.ssl.enable", "true");
I didn't get why are you using a Configuration class, if you are using spring boot 2 you could just put all the email configuration in your application.properties file: 我不明白为什么要使用Configuration类,如果您使用的是Spring Boot 2,则可以将所有电子邮件配置都放入application.properties文件中:
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.ssl.enable=true
spring.mail.host=smtp.yandex.ru
spring.mail.port=465
spring.mail.username=test@yandex.ru
spring.mail.password=test122223
Try this code: 试试这个代码:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try{
startActivity(Intent.createChooser(i, "Send mail..."));
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.",
Toast.LENGTH_SHORT).show();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.