从java应用程序发送电子邮件时出现异常:拒绝中继 [英] Exception in sending emails from java application : Relaying denied

查看:403
本文介绍了从java应用程序发送电子邮件时出现异常:拒绝中继的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Spring Mail从java应用程序发送电子邮件
org.springframework.mail.javamail.JavaMailSenderImpl

We are using Spring Mail to send emails from java application org.springframework.mail.javamail.JavaMailSenderImpl

Spring Email Configuration

Spring Email Configuration is

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl" autowire-candidate="default">
        <property name="host" value="${test.email.host}" />
        <property name="port" value="${test.email.port}" />
        <property name="username" value="${test.email.username}" />
        <property name="password" value="${test.email.password}" />
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.auth">true</prop>

            </props>
        </property>
    </bean>

Java代码快照

    @Autowired(required = true)
    @Qualifier("errorMessageMailSender")
    JavaMailSenderImpl mailSender;

    ..............
    ..............

          try {
                MimeMessage mailMessage = buildEmailMimeMessage(properties,mimeMultipart);
                logger.info(String.format("Built MimeMessage object is <%s>",mailMessage));
                if (mailMessage != null) {
                    mailSender.send(mailMessage);
                    logger.info("Mail sent Successfully");
                }else{
                    logger.info("Mail send failed as Mail message object construction failed.");
                }
                result=true;
            } catch (Exception e) {
                logger.error("An exception occurred while sending mail :: " + e.getMessage());
            }

物业档案

test.email.host=mail.mydomain.net
test.email.port=2525
test.email.username=demo@mydomain.net
test.email.password=mypassword

但我们低于例外,并且未发送电子邮件

But we are below exception, and email is not being sent

An exception occurred while sending mail :: Failed messages: javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 <demo@mydomain.net>... Relaying denied


推荐答案

您尝试发送邮件的smtp服务器拒绝中继。如果您自己的本地服务器不是问题,您可以更改配置以从mydomain.net中继邮件。但如果它是外部服务器(例如gmail),则必须使用真正的注册域。

The smtp server that you are trying to send the mail to is rejecting to relay. If it is your own local server that is not a problem, you may change configurations to relay mails from your mydomain.net . But if it is an external server (gmail for example), you have to use a real registered domain.

要针对邮件服务器测试代码,我建议你设置一个dockerized Apache James Server,在其上创建一些测试用户并发送和接收电子邮件。

To test your code against a mail server, I recommend you to setup a dockerized Apache James Server, create some test users on it and send and receive emails.

这篇关于从java应用程序发送电子邮件时出现异常:拒绝中继的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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