0

再会,

我是在一些免费的 Java 在线课程的帮助下自学的,而且对一切都非常陌生。

我正在努力运行一个代码,该代码旨在使用我的 PC 作为 localhost 发送具有设定内容的电子邮件。使用 Netbeans IDE,我不断得到以下信息:

"Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing return statement
    at SendEmail$Session.getDefaultInstance(SendEmail.java:29)
    at SendEmail$Session.access$000(SendEmail.java:27)
    at SendEmail.main(SendEmail.java:16)
C:\Users\ameer.hussein\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)"

我不确定该怎么做,因为我尝试了多种方法来克服这个问题并成功申请。我已经完成了我所知道的并且可以从我的笔记中指望的事情,但仍然不明白这个例外意味着什么。

我试图运行的代码:

public class SendEmail {

   public static void main(String [] args) {    
      String to = "example@email.com, example@email.com";
      String from = "example@email.com";
      String host = "localhost";
      Properties properties = System.getProperties();


      properties.setProperty("mail.smtp.host", host);


      Session session = Session.getDefaultInstance(properties);

      try

         MimeMessage message = new MimeMessage(session); 
         message.setFrom(new InternetAddress(from));  
         message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));         
         message.setSubject("This is the Subject Line!");
         message.setText("This is actual message");         
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }
   }


void addRecipients(Message.RecipientType type, Address[] addresses)
   throws MessagingException

有人可以帮我理解异常以及它发生的原因吗?

亲切的问候,阿米尔

4

0 回答 0