2017-09-07 106 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)