MAILX too much time to send email

Hello,
I am using heirloom-mailx on UBUNTU 11.04 to create a bash script that sends an e-mail with an attachment.
The command invoked is :

echo $BODY | mailx -v \
-S smtp=smtps://$smtpmailserver:465 \
-S from=$MITTENTE \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp-auth-user=$USER \
-S smtp-auth-password=$PASSWORD \
-s "$SUBJECT" \
-a $ATTACHMENT \
$RECIPIENT

The result is :

Resolving host xxxxxxxxxx . . . done.
Connecting to xxxxxxxxxx . . . connected.

Then I have to wait ONE MINUTE before it appears the following:

220 (mail-server) ESMTP ready
>>> EHLO svn
250-(mail-server)
250-AUTH CRAM-MD5 PLAIN LOGIN DIGEST-MD5 NTLM
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-PIPELINING
250-ETRN
250-DSN
250 HELP
>>> AUTH LOGIN
334 (string)
>>> (string)
334 (string)
>>> (string)
235 2.0.0 Authentication successful
>>> MAIL FROM:<(sender)>
250 2.1.0 Sender <(sender)> ok
>>> RCPT TO:<(recipient)>
250 2.1.5 Recipient <(recipient)> ok (local)
>>> DATA
354 Enter mail, end with CRLF.CRLF
>>> .
250 2.0.0 (string) Message accepted for delivery
>>> QUIT
221 2.0.0 SMTP closing connection

Do you know why there is such a delay? How can I reduce the sending time?
It is not linked to the attached file, I have to wait also if it is not present.

Thanks in advance for any reply.

This may be an anti-spam measure on the receiving side, trying stuff like doing a reverse-lookup on your IP.

1 Like

Do you think my IP has to belong to the net of the Sender mail domain?
How can I use rev-lookup for my purposes?

Thanks

What I was trying to say is, that it is probably not mailx taking the time, but the receiving server not responding earlier for whatever reason. If you don't have access to the server it may be out of your control. Can you connect to port 25 (or 587) via telnet and does the delay show there too?

1 Like

Ok, thanks I understood.
If I try to connect to port 25 via telnet I see:
Trying x.x.x.x...
Connected to x.x.x.x
Escape character is '^]'.

And probably after a while the "220" line. I just see hat there is a nifty telnet-ssl package too, so you can verify that it isn't mailx causing the delays with port 465 .

1 Like

Walter is correct - most likely the delay is on the mail server, especially if it is Exchange 2010 or later. We fixed the problem by defining the MAILHOST in /etc/hosts and making changes to sendmail.cf to force the connection to MAILHOST. This last part is nasty if you have never seen it before, and you may need to learn how to compile sendmail configuration files. It is way beyond something like a forum format.

This is a sample diff for what we did:

root /etc/mail> diff sendmail.cf  sendmail.keep.7.24.2014
22,25d21
< ##### built by root@SNEDWB02 on Thu Jul 17 09:53:55 MDT 2014
< ##### in /etc/mail/cf/cf
< ##### using ../ as configuration include directory
< #####
57,58d52
< ##
< #
59a54,55
>
>
94c90
< DSesmtp:mailhost.xxxxx.com
---
> DS
828c824
< # R$* < @ $* .$m. > $*        $#esmtp $@ $2.$m $: $1 < @ $2.$m. > $3
---
> R$* < @ $* .$m. > $*  $#esmtp $@ $2.$m $: $1 < @ $2.$m. > $3

1 Like

Thank you for your answers.

@jim_mcnamara
Mailx resolves quickly the IP of MAILHOST it is not a dns delay in my situation.
Regarding the sendmail.cf I will search around how to compile it.

Thank you for your time.

The problem we had was: exchange "refused" the mailx request and forwarded it OUT of the building and out of our domain. 20 minutes later the message came back in from the wild. The cause was not DNS but exchange settings. The MAILHOST thing forces exchange to accept the fact that yes, we are part of your domain, so send it NOW! We did this because our windows admins were not sure how to fix exchange.

sendmail is very complex - consider getting one of the O'Reilly books on sendmail.

1 Like