Script to send an e-mail with sendmail

freddiefreeloader

New Member


Messages: 2

#1
Hi people. Let me first introduce myself by saying that I'm a newbie to the FreeBSD, and almost any Unix/Linux too. I've looked anyway in the Handbook and Mailing lists for this. Having done the disclaimer, here's my issue:
I've set up a very modest home server, mainly used for my personal research satisfaction... it does not perform any crital tasks at all.
Ever since I installed it, FreeBSD reboots itself every 3 or 4 days without any warning or error message. I've written a very simple shell script in order to have it send an e-mail to different accounts when the server is restarted. However, I'm not getting those e-mails at all. They are bounced back because my (dinamic) "IP is not trusted". The line which send the mail reads:

$ cat mail.test | mail -s "server reboot notification" -F email@address.here

I guess this is a just a security feature against spam from GMail, Hotmail, etc, which I can obviously understand. But I cannot find a way to have the mail delivered! I do have a .forward file with my GMail e-mail address, and FreeBSD manges to get send me the daily check output without any issue.
Does anyone know why the e-mails I'm sending manually while running the script fail?
Thanks in advance.
 

keramida@

Member
Developer

Thanks: 7
Messages: 21

#2
However, I'm not getting those e-mails at all. They are bounced back because my (dinamic) "IP is not trusted".
Each email message is assigned a unique "Message-Id", and your /var/log/maillog file should include lines like:

Code:
Dec 12 05:43:26 kobe sm-mta[6151]: mBC3hQLw006151:
  from=<owner-freebsd-current@freebsd.org>, size=7765, class=0,
  nrcpts=1, msgid=<20081212034042.GL46707@cdnetworks.co.kr>,
  proto=ESMTP, daemon=Daemon0, relay=kobe.laptop [127.0.0.1]
Dec 12 05:43:26 kobe sm-mta[6152]: mBC3hQLw006151:
  to="|exec /usr/local/bin/procmail || exit 75",
  ctladdr=<keramida@localhost.laptop> (1000/1000),
  delay=00:00:00, xdelay=00:00:00, mailer=prog, pri=37971,
  dsn=2.0.0, stat=Sent
After the process ID at "sm-mta[6151]" and "sm-mta[6152]" there is an easy to locate identifier, mBC3hQLw006151 in this case. Can you grep using this sort of identifier and show us all the log entries for a message that fails?

I think you are trying to send directly to external SMTP servers, without passing through your Internet Service Provider's mail gateway. This won't work, but to be sure that this is indeed the case, we have to see the log file entries.
 
OP
OP
F

freddiefreeloader

New Member


Messages: 2

#3
I've read something like what you mentioned: I should first reach the SMTP server through my ISP's mail gateway. Don't quiet understand what that means anyway...
Here's the log:

Code:
Dec 11 21:05:35 hostname sendmail[37382]: mBBN44e0037382: to=gmail@account.com, ctladdr=root (0/0), delay=00:01:31, xdelay=00:01:30, mailer=relay, pri=30091, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat
=Sent (mBBN45q5037384 Message accepted for delivery)
Dec 11 21:06:08 hostname sm-mta[37389]: mBBN45q5037384: to=<gmail@account.com>, ctladdr=<root@hostname.netname> (0/0), delay=00:00:33, xdelay=00:00:33, mailer=esmtp, pri=30423, relay=gmail-smtp-in.l.googl
e.com. [209.85.163.27], dsn=5.0.0, stat=Service unavailable
Dec 11 21:06:08 hostname sm-mta[37389]: mBBN45q5037384: mBBN68q5037389: DSN: Service unavailable
Dec 11 21:06:40 hostname sm-mta[37389]: mBBN68q5037389: to=gmail@account.com, delay=00:00:32, xdelay=00:00:32, mailer=esmtp, pri=31447, relay=gmail-smtp-in.l.google.com. [209.85.163.27], dsn=2.0.0, stat=S
ent (OK 1229036812 h27si613187elf.16)
Dec 11 22:14:07 hostname sendmail[37590]: mBC0E6b5037590: from=username, size=126, class=0, nrcpts=1, msgid=<200812120014.mBC0E6b5037590@hostname.netname>, relay=username@localhost
Dec 11 22:15:37 hostname sm-mta[37591]: mBC0E7Jv037591: from=<username@hostname.netname>, size=487, class=0, nrcpts=1, msgid=<200812120014.mBC0E6b5037590@hostname.netname>, proto=ESMTP, daemon=Daemon0, rela
y=localhost [127.0.0.1]
Dec 11 22:15:37 hostname sendmail[37590]: mBC0E6b5037590: to=gmail@account.com, ctladdr=username (1001/1001), delay=00:01:31, xdelay=00:01:30, mailer=relay, pri=30126, relay=[127.0.0.1] [127.0.0.1], d
sn=2.0.0, stat=Sent (mBC0E7Jv037591 Message accepted for delivery)
Dec 11 22:16:10 hostname sm-mta[37596]: mBC0E7Jv037591: to=<gmail@account.com>, ctladdr=<username@hostname.netname> (1001/1001), delay=00:00:33, xdelay=00:00:33, mailer=esmtp, pri=30487, relay=gmail-s
mtp-in.l.google.com. [209.85.163.27], dsn=5.0.0, stat=Service unavailable
Dec 11 22:16:10 hostname sm-mta[37596]: mBC0E7Jv037591: mBC0GAJv037596: DSN: Service unavailable
Dec 11 22:16:10 hostname sm-mta[37596]: mBC0GAJv037596: to=<username@hostname.netname>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31511, relay=local, dsn=2.0.0, stat=Sent
Dec 12 00:00:00 hostname newsyslog[37809]: logfile turned over
For obvious reasons, I've replaced:
* my e-mail address by gmail@account.com
* server's name by hostname
* domain name by netname
 

keramida@

Member
Developer

Thanks: 7
Messages: 21

#5
It looks like your local Sendmail process tries to deliver *directly* to one of Google's mail servers. If you have a dynamic IP address this is very likely to fail (most sites now block dynamic IP address ranges, to avoid getting spammed).

You have to find out the hostname of your ISP's mail gateway, and then modify your "/etc/mail/HOSTNAME.mc" file (where "HOSTNAME" is the host name of your local machine) to enable the following option:

Code:
dnl Dialup users should uncomment and define this appropriately
define(`SMART_HOST', `your.isp.mail.server')
Replace your.isp.mail.server with the hostname of the mail gateway your ISP uses (note that there are two types of quote characters in that line; make sure you use the right type of opening and closing quote), save the HOSTNAME.mc file, and then run as root:

Code:
# cd /etc/mail
# make all && make restart
If you don't know the right hostname for the mail gateway of your ISP, you will have to ask them. It is commonly something like "mail.ispdomain.com", "mailgate.ispdomain.com" or "smtp.ispdomain.com", but it doesn't hurt to ask.
 
Top