JavaMail的不工作在Amazon EC2 [英] JavaMail Not Working on Amazon EC2

查看:197
本文介绍了JavaMail的不工作在Amazon EC2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


问题:

我想使用JavaMail来从EC2发送电子邮件的Ubuntu 12.04服务器,但它不工作。


背景:

我打算送一个自动生成的邮件从Tomcat服务器到几个团队成员。我用的JavaMail 1.4.7完成这个任务,我已经成功试图在本地安装的Tomcat(在个人笔记本电脑)。

接下来的步骤是,我把这个模块中的EC2服务器上,但它开始与下面给出错误失败:


错误:

DEBUG SMTP:AUTH登录失败 javax.mail.AuthenticationFailedException:535-5.7.1用户名和密码不被接受。了解更多 535 5.7.1 <一个href="http://support.google.com/mail/bin/answer.py?answer=14257">http://support.google.com/mail/bin/answer.py?answer=14257 j13sm1603739pat.17 - gsmtp

 在com.sun.mail.smtp.SMTPTransport $ Authenticator.authenticate(SMTPTransport.java:826)
在com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
在com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
在javax.mail.Service.connect(Service.java:295)
在javax.mail.Service.connect(Service.java:176)
 


code段:

  Security.addProvider(新com.sun.net.ssl​​.internal.ssl.Provider());
属性道具=新特性();
props.put(mail.smtps.host,smtp.gmail.com);
props.put(mail.transport.protocol,SMTP);
props.put(mail.smtps.auth,真);
props.put(mail.smtp.debug,真);
props.put(mail.smtp.port,465);
props.put(mail.smtp.socketFactory.port,465);
props.put(mail.smtp.socketFactory.class,javax.net.ssl​​.SSLSocketFactory);
props.put(mail.smtp.socketFactory.fallback,假);
props.put(mail.smtp.ssl.enable,真正的);

会话会话=作为Session.getDefaultInstance(道具);
session.setDebug(调试);

消息味精=新的MimeMessage(会议);
网际addressFrom =新的网际(fromId@gmail.com);
msg.setFrom(addressFrom);

网际[] addressTo =新的网际[recipients.length]
的for(int i = 0; I&LT; recipients.length;我++){
addressTo [我] =新的网际(收件人[I]);
}
msg.setRecipients(Message.RecipientType.TO,addressTo);
msg.setSubject(考试科目);
msg.setContent(测试信息,text / plain的);
交通运输TP = session.getTransport(SMTP);
tp.connect(SMTP_HOST_NAMEdummyId@gmail.com,dummypassword);
tp.sendMessage(味精,addressTo);
tp.close();
 


附加信息:

  1. 我已经添加权限的EC2实例的所有端口。另外,我对端口465(SMTPS)和25(SMTP)加入明确的权限。
  2. 在我有交叉检查,在code提供的用户名和密码的正确性。
解决方案

在过去,垃圾邮件从服务器中的EC2发一直为亚马逊和邮件服务提供商的一大难题。最初,亚马逊有意必须通过普通电子邮件服务反垃圾邮件检查(缺少DNS反向搜索PTR记录)不足DNS信息,那么亚马逊推出的低邮件限额,依次审批流程,以充分使用EC2或SES邮件(提供具体技术设置完全启用外发电子邮件)。

下面的描述了一些历史上的一个链接:的http:// shlomoswidler .COM / 2009/07 /发送,电子邮件从-ec2.html

当你得到的错误是一个失败的认证,在Gmail的服务器,它可能是(可能是的),因为Gmail的标识发送方的IP地址作为一个潜在的垃圾邮件发送者,因为你没有设置亚马逊正确反向DNS查找属性。

  1. 设置亚马逊反向DNS查找细节,让你的邮件不被检测为垃圾邮件的Gmail。看来这只能通过提交申请表解除电子邮件发送配额来完成。从亚马逊EC2 IP信息常见问题:

      

    问:我可以配置反向DNS记录我的弹性IP地址

         

    是的,你可以配置你的弹性IP的反向DNS记录   地址(提交的<一个href="http://portal.aws.amazon.com/gp/aws/html-forms-controller/contactus/ec2-email-limit-rdns-request"相对=nofollow>请求删除电子邮件发送限制   表格)。请注意,相应的正向DNS记录指向   该弹性IP地址必须存在,才可以创建反向   DNS记录。

    下面是当一个电子邮件配额用尽送出亚马逊的电子邮件的一个例子 - 再次阐明的要求和放大器;批准DNS PTR配置: http://www.practicalclouds.com/content /引导/发送,电子邮件的EC2实例

  2. precisely遵循所有的链接包含在你的Gmail错误信息说明: http://support.google.com/mail/bin/answer.py?answer=14257 。这将重置您的Gmail帐户状态,如果Gmail认为您的帐户是由您的IP地址发送垃圾邮件。

  3. 另外,您可以通过亚马逊SES,还需要申请,批准和适当的亚马逊提供的配置发送邮件。这使得邮件通过 com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.sendEmail 发送。如果您使用此,为你的code到sendmail的补充授权:<一href="http://stackoverflow.com/questions/11155921/unable-to-send-email-from-amazon-ec2-server-in-java">Unable从亚马逊EC2服务器中的Java 发送电子邮件。


PROBLEM:

I'm trying to use JavaMail to send email from an EC2 Ubuntu 12.04 Server but it's not working.


BACKGROUND:

I intend to send an auto generated mail from a Tomcat Server to a few team members. I used JavaMail 1.4.7 for this task and I've successfully tried it on a local installation of Tomcat (on a personal laptop).

The next step was where I put this module on an EC2 Server but it started failing with the below given error:


ERROR:

DEBUG SMTP: AUTH LOGIN failed javax.mail.AuthenticationFailedException: 535-5.7.1 Username and Password not accepted. Learn more at 535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 j13sm1603739pat.17 - gsmtp

at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)


Code Snippet:

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props = new Properties();
props.put("mail.smtps.host","smtp.gmail.com");
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtps.auth", "true");
props.put("mail.smtp.debug", "true");
props.put("mail.smtp.port", 465);
props.put("mail.smtp.socketFactory.port", 465);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.ssl.enable", true);

Session session = Session.getDefaultInstance(props);
session.setDebug(debug);

Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress("fromId@gmail.com");
msg.setFrom(addressFrom);

InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject("test subject");
msg.setContent("test message", "text/plain");
Transport tp = session.getTransport("smtp");
tp.connect(SMTP_HOST_NAME, "dummyId@gmail.com", "dummypassword");
tp.sendMessage(msg, addressTo);
tp.close();


ADDITIONAL INFO:

  1. I've added permissions for all ports on the EC2 instance. Also, I've added explicit permissions for ports 465(SMTPS) and 25(SMTP).
  2. I've cross checked the correctness of the username and password provided in the code.

解决方案

In the past, spam sent from servers within EC2 has been a major problem for both Amazon and mail service providers. Initially, Amazon deliberately had insufficient DNS information to pass anti-spam checking of common email services (lack of DNS reverse lookup PTR records), then Amazon introduced low mail quotas, followed approval processes to give full access to EC2 or SES mail (provides specific technical setup to fully enable outgoing email).

Here's a link describing some of the history: http://shlomoswidler.com/2009/07/sending-email-from-ec2.html

While the error you're getting is a failed authentication at Gmail server, it may be (probably is) because Gmail identifies your sender IP address as a potential spammer, because you didn't setup Amazon reverse DNS lookup properties correctly.

  1. Setup Amazon Reverse DNS lookup details, so that your mail is not detected as spam by Gmail. It seems this can only be done by submitting a request form to lift Email Sending quota. From Amazon EC2 IP Information FAQs:

    Q: Can I configure the reverse DNS record for my Elastic IP address?

    Yes, you can configure the reverse DNS record of your Elastic IP address (submit the Request to Remove Email Sending Limitations Form). Note that a corresponding forward DNS record pointing to that Elastic IP address must exist before we can create the reverse DNS record.

    Here's an example of an email sent out by Amazon when an email quota is exhausted - again spelling out request & approval for DNS PTR configuration: http://www.practicalclouds.com/content/guide/sending-email-ec2-instances

  2. Precisely follow all the instructions in the link included in you Gmail error message: http://support.google.com/mail/bin/answer.py?answer=14257. This will reset your Gmail account status, if Gmail thinks your account is spamming from your IP address.

  3. Alternatively, you can send mail via Amazon SES, also requiring request, approval and appropriate Amazon-provided configuration. This allows mail to be sent via com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.sendEmail. If you use this, add authorisation for your code to sendmail: Unable to send email from Amazon EC2 Server in Java.

这篇关于JavaMail的不工作在Amazon EC2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆