为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我不能发送电子邮件?

为什么我不能发送电子邮件?

手掌心 2023-03-23 13:44:19
我面临无法发送电子邮件的事实。我不明白原因。我使用 Spting Boot 2。该示例使用 JavaMailSender 类。但是你可以不用它的实现和在 application.properties 中指定的必要参数吗?@Configurationpublic 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;    }}2 分钟后,出现错误:"javax.mail.MessagingException: Could not connect to SMTP host"
查看完整描述

2 回答

?
侃侃无极

TA贡献2051条经验 获得超10个赞

尝试添加


spring.mail.properties.mail.smtp.ssl.enable=true

或者


props.put("mail.smtp.ssl.enable", "true");

我不明白你为什么要使用配置类,如果你使用的是 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


查看完整回答
反对 回复 2023-03-23
?
江户川乱折腾

TA贡献1851条经验 获得超5个赞

试试这个代码:


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();

   }


查看完整回答
反对 回复 2023-03-23
  • 2 回答
  • 0 关注
  • 102 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信