java - 邮件触发时出错

标签 java email smtp

我有邮件触发程序。我拥有从我的机器到 SMTP 服务器的邮件触发器的访问权限。即使我也能够 telnet 并 ping 到 10.242.175.70/25 。但是当我在机器上运行程序时,我遇到如下错误。请帮助我解决这个问题,并让我知道我做错了什么。我已经提供了 activatio.jar 和 mail.jar,如果我缺少任何其他 jar,请也告诉我。

enter image description here

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendEmail
{
   public static void main(String [] args)
   {    
      // Recipient's email ID needs to be mentioned.
      String to = "mohit.darmwal@cognizant.com";

      // Sender's email ID needs to be mentioned
      String from = "mohit.darmwal@cognizant.com";

      // Assuming you are sending email from localhost
      String host = " 10.243.33.234";//"localhost";//"192.168.195.68";

      // Get system properties
      Properties properties = System.getProperties();

      // Setup mail server
      properties.setProperty("10.242.175.70", host);

      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);

      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);

         // Set From: header field of the header.
         message.setFrom(new InternetAddress(from));

         // Set To: header field of the header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         // Set Subject: header field
         message.setSubject("This is the Subject Line!");

         // Now set the actual message
         message.setText("This is actual message");

         // Send message
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}

最佳答案

结账 JavaMail API供引用要设置哪些属性以及如何填充它们。

本例中的具体错误是主机名设置错误:

  // Setup mail server
  //Does not work this way:
  //properties.setProperty("10.242.175.70", host);           
  //Use correct property name
  properties.setProperty("mail.smtp.host", "10.242.175.70"); 

关于java - 邮件触发时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31043789/

相关文章:

java - 如何在彼此正下方添加 JLabel 序列?

Java 类型 : What is the format for representing a variable of type `Date` ? `Time` ?

wordpress - 如何使用wp_mail邮件发送附件邮件

c# - smtp异常发送邮件失败?

smtp 无法在生产环境中工作,即使有凭据也未经过身份验证

delphi - 如何在没有 HTTP 的情况下在 Delphi 中创建和处理 SOAP 请求?

java - 设置 SWT.FULL SELECTION 时,SWT TreeViewer 同时展开和折叠

java - 从查询更新 JTable

mysql - 邮件消息中的数组和变量

java - 使用 Java 在 Mac 上以编程方式发送电子邮件(通过 Mac 邮件客户端)