apache james:邮件服务器

时间:2017-09-07 11:06:09

标签: java mail-server james

以下是我的代码。 这成功执行了。但是我的收件箱里没有收到任何邮件 有人请帮忙。

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


        String fromAddress = "testmail@gmail.com";   
        String toAddress = "testmail@gmail.com";        
        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();     
        } 
        }
}

1 个答案:

答案 0 :(得分:0)

您需要登录并通过以下方式之一发送:

  • POP
  • IMAP
  • Gmail API

或者您可以使用您控制的域,在您尝试作为gmail.com发送时,并因为它知道您的IP不允许以gmail.com身份发送而被忽略,因为SPF ,通过设置谁可以发送哪些域

来限制垃圾邮件

SPF (Wikipedia)