如何从不同的域发送电子邮件

时间:2014-07-08 21:06:37

标签: java javamail

我正在创建一个应用程序,用户应该能够通过电子邮件发送一些报告。我需要用户能够指定他/她的电子邮件地址以及程序设置必要的属性。我的代码在用户使用Gmail帐户时有效。这是代码的一部分:

final String password = "password";
                        Properties props = new Properties();
                        //gmail
                        props.put("mail.smtp.starttls.enable", "true");
                        props.put("mail.smtp.auth", "true");
                        props.put("mail.smtp.host", "smtp.gmail.com");
                        props.put("mail.smtp.port", "587");
                        Session session = Session.getInstance(props,
                          new javax.mail.Authenticator() {
                            protected PasswordAuthentication getPasswordAuthentication() {
                                return new PasswordAuthentication(username, password);
                            }
                        });

以上作品。当我尝试从GoDaddy托管电子邮件发送时,我遇到了问题。我将以下代码用于goDaddy电子邮件:

final String password = "password";
                        Properties props = new Properties();
                        //GoDaddy
                        props.put("mail.smtp.starttls.enable", "true");
                        props.put("mail.smtp.auth", "true");
                        props.put("mail.smtp.host", "smtpout.secureserver.net");
                        props.put("mail.smtp.port", "80");
                        Session session = Session.getInstance(props,
                          new javax.mail.Authenticator() {
                            protected PasswordAuthentication getPasswordAuthentication() {
                                return new PasswordAuthentication(username, password);
                            }
                        });

当我尝试上述内容并转到目标电子邮件时,我找不到任何内容,但是当我检查GoDaddy电子邮件的收件箱(应该是发件人电子邮件)时,我会在收件箱中找到邮件传送系统消息当以下内容:     (返回码550] sid:PwwN1o00B0bi6P901 :: 5.7.1更多信息.cm5si19503077pac.22 - gsmtp)。 有人可以告诉我这是什么问题吗?感谢。

3 个答案:

答案 0 :(得分:0)

问题在于返回代码550.此返回代码通常意味着服务器无法传递邮件,因为它尝试发送到的收件箱不存在。我会弄清楚在使用GoDaddy时导致错误代码的原因,并尝试使用不同的电子邮件提供商的代码。

http://www.serversmtp.com/en/error-550

答案 1 :(得分:0)

From(解释了各种SMTP错误代码)[http://support.mailhostbox.com/email-administrators-guide/error-codes]它是以下之一:

550 5.7.1 : Helo command rejected: You aren't localhost.
550 5.7.1 : Helo command rejected: You aren't localhost.localdomain.
550 5.7.1 : Helo command rejected: You are not me
Our servers do not accept SMTP HELO command as HELO localhost or HELO localhost.localdomain or HELO . We accept HELO from a valid Domain Name or your computer name which is other than your domain name. Please check with your ISP or Mail administrator for this issue.

550 5.7.1 Service unavailable; client [a.b.c.d] blocked using rbl.mailhostbox.com
rbl.mailhostbox.com is an inhouse RBL zone which we use to protect our services from inbound attacks. If you encounter any of the above messages, you can whitelist the IP using http://whitelist.mailhostbox.com/
To avoid misuse of this feature, an IP is allowed to be white-listed only a defined number of times. If you face any issues feel free to contact our support helpdesk with the details.

答案 2 :(得分:0)

大多数邮件服务器都不允许您使用任意发件人地址发送电子邮件。如果他们这样做,他们将被用于垃圾邮件,网络钓鱼等。你有一些选择......

  1. 找一个可以让你这样做的服务。祝你好运!
  2. 运行您自己的邮件服务器。显然很多工作。
  3. 询问用户自己的邮件服务器的所有登录信息,并通过他们自己的邮件服务器发送邮件。用户可能不会喜欢这个。
  4. 以与您的应用程序关联的用户身份发送报告,而不是最终用户。