Skip to content

Sender address rejected: Access denied

by on November 12, 2013

i was trying to enable sending mail from my linuxes to my email and got the rejection.

I’m using postfix and set up the relayhost correctly.

examining the rejection I see that the host contains localdomain and this causes the rejection.

I am able to send mail using telnet to the mail server (telnet IP 25), so, searching around I wrote some expect script to send mail – see below.

BUT – although it is nice to play with expect, i wanted to send mails using mail command, so I’ve find what to change in the config files:

just read the /etc/postfix/generic file and follow the explanation about localdomain…
i.e.,

  • add a line to this file “@host.localdomain      @hhost.company.com
  • to the /etc/postfix/main.cf file add a line “smtp_generic_maps = hash:/etc/postfix/generic
  • run the command: postmap  /etc/postfix/generic
  • restart the service: service postfix restart
  • and voila: id | mail -s `hostname` myaddress@mycompany.com

 

and here is the promised expect script named my_mail.sh

using it: ./my_mail.sh “me@example.com” “my subject” “my text”
or – if you want to send a file – ./my_mail.sh “me@example.com” “my subject” “`cat myfile`”

 

#!/usr/bin/expect -f

log_user 1

set prompt {\$ $}
set mailto [lindex $argv 0]
set subject [lindex $argv 1]
set message [lindex $argv 2]

#puts $subject $message
spawn telnet 192.168.30.193 25
expect “*?assword:*”
expect “Trying 192.168.30.193…”
expect “Connected to 192.168.30.193.”
expect “Escape character is ‘^]’.”
expect “220 ******************************”
send “HELO h85\r”
expect “Now try logging*”
expect “250 .*”
send “MAIL FROM: mail@host\r”
expect “250 2.1.0 Ok”
send “RCPT TO: $mailto\r”
expect “250 2.1.5 Ok”
send “DATA\r”
expect “354 End data with <CR><LF>.<CR><LF>”
send “SUBJECT: $subject\r”
send “$message\r”
send “\r”
send “.\r”
expect “250 2.0.0 Ok: queued as 7E5DD18067”
send “quit\r”
expect “221 2.0.0 Bye”
expect “Connection closed by foreign host.”

 

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: