2017-09-07 107 views
0

以下是我的代碼。 這成功執行。但我在收件箱中沒有看到任何郵件 有人請幫忙。apache james:郵件服務器

import java.util.*; 
import javax.mail.*; 
import javax.mail.internet.*; 
public class SendMail { 
     public static void main(String args[]) throws Exception { 


     String fromAddress = "[email protected]"; 
     String toAddress = "[email protected]";   
     Properties properties = new Properties();  
     properties.put("mail.smtp.host", "localhost");  
     properties.put("mail.smtp.port", "25");  
     properties.put("mail.transport.protocol", "smtp"); 


     try    
     {   
      properties.put("mail.smtp.starttls.enable", "true"); 

      Session session = Session.getDefaultInstance(properties, null); 

      Message message = new MimeMessage(session);   
      message.setFrom(new InternetAddress(fromAddress));   
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toAddress));   
      message.setSubject("Email from our JAMEs");   
      message.setText("hiiiiii!!");   
      Transport.send(message);   
      System.out.println("Email sent");  
     }  
     catch (MessagingException e)  
     {   
      e.printStackTrace();  
     } 
     } 
} 

回答

0

你要麼需要登錄和傳送過來的一個:

  • POP
  • IMAP
  • Gmail的API

,或者您可以使用域你控制,此時您正試圖發送gmail.com,並且被忽略,因爲它知道您的IP不允許作爲發送3210,因爲SPF通過設置誰可以發送哪個域名來限制垃圾郵件

SPF (Wikipedia)