亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我不能發送電子郵件?

為什么我不能發送電子郵件?

手掌心 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("[email protected]");        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

[email protected]

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[]{"[email protected]"});

   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 關注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號