簡體   English   中英

通過電子郵件錯誤以Java發送SMS文本

[英]Sending SMS Text in Java via Email Error

我試圖在Java中通過電子郵件發送文本消息。

當我使用以下方法通過Outlook執行此操作時,效果很好。

通過電子郵件發送短信指南

但是,當我使用JavaMail在Java中嘗試使用它時,我得到了:

java.mail.SendFailedException:無效的地址

Properties props = new Properties();
props.put("mail.smtp.host", "mail.xxxx.org");
props.put("mail.transport.protocol", "smtp");
Session session = Session.getInstance(props, null);

String msgBody = "You have a new message.";

try {
       javax.mail.Message msg = new MimeMessage(session);
       msg.setFrom(new InternetAddress("myemail@email.com", "Email Name"));
       msg.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("5417061233@vtext.com", "Phone"));


       msg.setSubject("New Message.");
       msg.setContent(msgBody, "text/plain");
       Transport.send(msg);

 } 
 catch (Exception e) {
       // ...           
 }

當我換線時

msg.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("5417061233@vtext.com", "Phone"));

msg.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("myemail@email.org", "Phone"));

它工作正常。

任何幫助或提示將不勝感激。

謝謝。

我建議檢查SMTP。 通常,SMTP允許您即使未登錄也可以在自己的域中發送電子郵件,但是他們希望登錄名可以在外部發送電子郵件。

在這里(http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/),您可以找到有關如何從gmail發送需要身份驗證的電子郵件的示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM