LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-19-2013, 08:50 PM   #1
crazylyle
LQ Newbie
 
Registered: Jun 2009
Posts: 4

Rep: Reputation: 0
Using sendmail from a script to email


I run a desktop Linux system at home. My network connection is thru Time-Warner Roadrunner. They provide an smtp server that I can send email out to the net thru. I have a script that runs twice a day, gathers up information from my machine and emails it to hotmail.com, so that I can read it at work on an iPad. This all worked fine until two days ago. The only thing on my end that happened about then was a power outage that caused my machine to reboot, so I assume that Time-warner has changed how they react to me e-mailing thru their smtp server.

My script basically creates an entire mail message, complete with From: and To: lines, and then uses

/usr/sbin/sendmail -t < /tmp/Xmail.$$

to mail it out.

If I try to do this by hand, with a minimal mail file that just says

To: james.lyle.peterson@hotmail.com
From: James Peterson <lyle@austin.rr.com>

and add a "-v" flag to the sendmail command, I can see that the smtp server is complaining

>>> MAIL From:<crazylyle@austin.rr.com> AUTH=crazylyle@localhost.localdomain
550 Invalid sender address rejected NSA [R0107006]

which makes sense to me. On my local machine, I am "crazylyle" (I tried to choose an ID that no one else in the world would want), but to my ISP I am lyle@austin.rr.com.

To get this to work, I clearly need to translate my local ID "crazylyle" to "lyle@austin.rr.com".

sendmail, when it is sending outgoing mail, uses /etc/mail/submit.cf to control how it works. There are two types of mappings that can be defined to map a local user ID to a remote user ID. The first of those, that most of the documentation talks about, is aliases and masquerading, but that really only affects incoming mail. None the less, I have turned on masquerading and alias:

define(`ALIAS_FILE', `/etc/aliases')dnl
MASQUERADE_AS(`austin.rr.com')dnl
FEATURE(`allmasquerade')dnl
FEATURE(`local_no_masquerade')dnl
FEATURE(`masquerade_envelope')dnl
FEATURE(always_add_domain)dnl

in my submit.mc. This seems to do nothing (as expected).

For outgoing mail, as I understand it, the important part is the Generics table, and I have that turned on too:

FEATURE(`genericstable')dnl
GENERICS_DOMAIN(`localhost.localdomain austin.rr.com')dnl

and my generics table file is:

crazylyle lyle@austin.rr.com
crazylyle@austin.rr.com lyle@austin.rr.com
crazylyle@localhost.localdomain lyle@austin.rr.com

trying to say that if you ever see crazylyle, under any circumstances, convert it to lyle@austin.rr.com

But still when I run sendmail -v, it does the same:

>>> MAIL From:<crazylyle@austin.rr.com> AUTH=crazylyle@localhost.localdomain
550 Invalid sender address rejected NSA [R0107006]

I found a page that listed debug flags for sendmail and have tried

sendmail -v -d0.12 -d1.12 -d11.12 -d12.12 -d13.12 -d14.12 -d16.12 -d19.12 -d21.12 -d27.12 -d28.12 -d30.12 -d31.12 -d36.12 -d37.12 -d45.12 -d47.12 -d60.12 -d95.12 -t < /tmp/outgoing

and looking at the log, I can see that "crazylyle" is not being translated to "lyle@austin.rr.com".

I found a page that explained how you can run sendmail by hand, and ask it to do translations:

# sendmail -v -bt -Csubmit.cf
> tryflags HS
> /try esmtp crazylyle

There are 4 types of flags, that affect what tables are used to do the translation: H (Header), E (Envelope), S (Sender), or R (Recipient). When I do this, and then change the flags, try it again, change the flags, try it again, ... It fails to do the translation for awhile, and then some combination of the flags, or some sequence of them, will cause it to start translating correctly, at least for some of the flags (even some that it failed to work with before). My best explanation of this was initialized memory, but running this under valgrind does not show any issues with memory or pointers.

This can't be that hard. Clearly, there must be lots of people who have ISPs and their local IDs are different from their IDs at the ISP, and some of them must try to email out. The web pages I have found that suggest how it is done all seem to indicate that what I have done should work. But it doesn't.

I don't even understand how it knows that I am crazylyle. I have "su -" to root, then to another user, then back to root, so that I am running as root, from another user. There is nothing left in an env variable that says that I am "crazylyle". The message I am trying to send out only says "from lyle@austin.rr.com" to "james.lyle.peterson@hotmail.com", but still the first (and most common) translation that shows up in the logs is:

rewrite: ruleset canonify input: crazylyle
...
rewrite: ruleset canonify returns: crazylyle

That's the first occurrence of "crazylyle" in the log, and there is no suggestion of where it comes from.

I've worked all day on this, and got nowhere. Any suggestions of where I'm going wrong?
 
Old 10-20-2013, 05:59 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Was your hostname localhost.localdomain before rebooting?
 
Old 10-20-2013, 06:47 PM   #3
crazylyle
LQ Newbie
 
Registered: Jun 2009
Posts: 4

Original Poster
Rep: Reputation: 0
> Was your hostname localhost.localdomain before rebooting?

Yes. I give my machine an id "jkl", but nothing seems to care about it. Since everything is very generic, and no one ever refers to my machine by name -- all internet access is initiated by my machine out, never someone else in, it doesn't matter. And the standard sendmail scripts seem to be all set up to handle this as a local machine name.
 
Old 10-21-2013, 05:18 PM   #4
crazylyle
LQ Newbie
 
Registered: Jun 2009
Posts: 4

Original Poster
Rep: Reputation: 0
I don't know what is, or is not, happening with the mappings, but I found a work-around to my problem.

Instead of letting sendmail try to guess what to do, and setting up tables to try to map things, instead, I can use the -f option to tell sendmail exactly what I want it to do:

/usr/sbin/sendmail -flyle@austin.rr.com -t < /tmp/Xmail

where the -f option tells it the name to use as the user that is sending the mail (the "from" ID).

And this gets Time Warner to accept who is sending the mail.
 
  


Reply

Tags
sendmail rewrite



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pipe email to extract attachments. Script works, but email sender receives an error! ceashton Linux - Server 4 01-08-2019 11:13 AM
[SOLVED] Sendmail is not sending email from PHP script. [RESOLVED] frigy Linux - Software 5 09-13-2010 01:08 PM
run a shell script/cronjob when any email arrive to specific email address ikillu Linux - General 3 05-30-2009 08:18 AM
sending email from a script without sendmail tangle Linux - Networking 1 12-06-2005 01:32 AM
Creating A Second Email Address For Email Account On Sendmail treedstang Linux - Software 1 04-27-2004 10:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration