552 sorry, your envelope sender domain must exist

2019-08-12 08:46发布

问题:

I'm not able to send a mail using ovh smtp server and spring integration.

Configuration looks good to me, what am I missing?

<int-mail:outbound-channel-adapter
    id="myOutboundMailChannelAdapter"
    channel="outboundMailChannel"
    mail-sender="mailSender" />

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="ns0.ovh.net"/>
    <property name="port" value="587"/>
    <property name="username" value="myUsername"/>
    <property name="password" value="myPass"/>
    <property name="javaMailProperties">
        <props>
            <prop key="mail.transport.protocol">smtp</prop>
            <prop key="mail.smtp.auth">true</prop>
            <prop key="mail.smtp.starttls.enable">true</prop>
            <prop key="mail.debug">true</prop>
        </props>
    </property>
</bean>

following the detailed log:

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
> DEBUG SMTP: useEhlo true, useAuth true
> DEBUG SMTP: trying to connect to host "ns0.ovh.net", port 587, isSSL false
> 220 ns0.ovh.net You connect to mail191 ESMTP
> DEBUG SMTP: connected to host "ns0.ovh.net", port: 587
> EHLO Marcello-PC.lan
> 250-ns0.ovh.net You connect to mail191
> 250-AUTH LOGIN PLAIN
> 250-AUTH=LOGIN PLAIN
> 250-STARTTLS
> 250-8BITMIME
> 250 SIZE 109000000
> DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
> DEBUG SMTP: Found extension "AUTH=LOGIN", arg "PLAIN"
> DEBUG SMTP: Found extension "STARTTLS", arg ""
> DEBUG SMTP: Found extension "8BITMIME", arg ""
> DEBUG SMTP: Found extension "SIZE", arg "109000000"
> STARTTLS
> 220 ready for tls
> EHLO Marcello-PC.lan
> 250-ns0.ovh.net You connect to mail191
> 250-AUTH LOGIN PLAIN
> 250-AUTH=LOGIN PLAIN
> 250-8BITMIME
> 250 SIZE 109000000
> DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
> DEBUG SMTP: Found extension "AUTH=LOGIN", arg "PLAIN"
> DEBUG SMTP: Found extension "8BITMIME", arg ""
> DEBUG SMTP: Found extension "SIZE", arg "109000000"
> DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
> DEBUG SMTP: AUTH LOGIN command trace suppressed
> DEBUG SMTP: AUTH LOGIN succeeded
> DEBUG SMTP: use8bit false
> MAIL FROM:
> 552 sorry, your envelope sender domain must exist [mail191] (#5.7.1)
> DEBUG SMTP: got response code 552, with response: 552 sorry, your envelope sender domain must exist [mail191] (#5.7.1)
> RSET
> 250 flushed
> DEBUG SMTP: MessagingException while sending, THROW:
> com.sun.mail.smtp.SMTPSendFailedException: 552 sorry, your envelope sender domain must exist [mail191] (#5.7.1)

回答1:

It looks like the formatting of your post hid the email address in the MAIL FROM: line. What address did you set as the From address of your message? Based on the error message, it looks like it's using a domain name that doesn't exist.



回答2:

The message you're sending to the outbound adapter needs a from header. There's a bunch of headers you can set up...

<int-mail header-enricher input-channel="literalValuesInput">
    <to value="test.to"/>
    <cc value="test.cc"/>
    <bcc value="test.bcc"/>
    <from value="test.from"/>
    <reply-to value="test.reply-to"/>
    <subject value="test.subject"/>
    <attachment-filename value="foo.txt"/>
    <multipart-mode value="1"/>
</header-enricher>

Of course, email addressed have to be in valid domains for most SMTP servers to accept them.