Networking Forums

Networking Forums > Computer Networking > Linux Networking > Sending email from command line?

Reply
Thread Tools Display Modes

Sending email from command line?

 
 
Gilles Ganault
Guest
Posts: n/a

 
      11-13-2007, 01:25 AM
Hello

I'm running Ubuntu 7.04 Server to which I need to add e-mail
capability. I installed Postfix through "apt-get install postfix",
edited /etc/postfix/main.cf.

Since I couldn't figure out how to use the sendmail command, I
installed mailutils... but failed finding examples on how to use
/usr/bin/mail with all the fields set from the command line:

echo "Call from customer X" | mail -s "Call from customer X" -f
(E-Mail Removed) (E-Mail Removed):

ubuntu postfix/smtp[10213]: D24476343E1: to=<(E-Mail Removed)>,
relay=smtp.isp.tld [some_ip_here]:25, delay=0.37,
delays=0.08/0.04/0.22/0.03, dsn=5.0.0, dUmMy=bounced (host
smtp.isp.tld[some_ip_here] said: 504 <root@acme>: Sender address
rejected: need fully-qualified address (in reply to MAIL FROM
command))

Is it possible to specify the FROM and TO fields from the command
line, and if yes, how?

Thank you.
 
Reply With Quote
 
 
 
 
Allen McIntosh
Guest
Posts: n/a

 
      11-13-2007, 01:38 AM
> echo "Call from customer X" | mail -s "Call from customer X" -f
> (E-Mail Removed) (E-Mail Removed):
>
> ubuntu postfix/smtp[10213]: D24476343E1: to=<(E-Mail Removed)>,
> relay=smtp.isp.tld [some_ip_here]:25, delay=0.37,
> delays=0.08/0.04/0.22/0.03, dsn=5.0.0, dUmMy=bounced (host
> smtp.isp.tld[some_ip_here] said: 504 <root@acme>: Sender address
> rejected: need fully-qualified address (in reply to MAIL FROM
> command))
>
> Is it possible to specify the FROM and TO fields from the command
> line, and if yes, how?


The "to" address was OK, as the transcript shows. -f doesn't do what
you think it does. It's hard to fiddle with the "from" address. If it
was easy, it would be even easier to forge. I suspect it is possible to
fix the domain name (which is what postfix is complaining about) but
I'll leave that for someone who knows postfix to address. Making sure
there is a fully qualified name in /etc/hosts might be a good start.
 
Reply With Quote
 
buck
Guest
Posts: n/a

 
      11-13-2007, 05:04 AM
On Mon, 12 Nov 2007 21:38:29 -0500, Allen McIntosh
<(E-Mail Removed)> wrote:

>> echo "Call from customer X" | mail -s "Call from customer X" -f
>> (E-Mail Removed) (E-Mail Removed):
>>
>> ubuntu postfix/smtp[10213]: D24476343E1: to=<(E-Mail Removed)>,
>> relay=smtp.isp.tld [some_ip_here]:25, delay=0.37,
>> delays=0.08/0.04/0.22/0.03, dsn=5.0.0, dUmMy=bounced (host
>> smtp.isp.tld[some_ip_here] said: 504 <root@acme>: Sender address
>> rejected: need fully-qualified address (in reply to MAIL FROM
>> command))
>>
>> Is it possible to specify the FROM and TO fields from the command
>> line, and if yes, how?

>
>The "to" address was OK, as the transcript shows. -f doesn't do what
>you think it does. It's hard to fiddle with the "from" address. If it
>was easy, it would be even easier to forge. I suspect it is possible to
>fix the domain name (which is what postfix is complaining about) but
>I'll leave that for someone who knows postfix to address. Making sure
>there is a fully qualified name in /etc/hosts might be a good start.


What's wrong with configuring a text file containing
`From: (E-Mail Removed)ess
Subject: How to send email
To: (E-Mail Removed)

This is the message'

And then send that with `sendmail --t < file'
?
--
buck

 
Reply With Quote
 
Moe Trin
Guest
Posts: n/a

 
      11-13-2007, 06:56 PM
On Tue, 13 Nov 2007, in the Usenet newsgroup comp.os.linux.networking, in
article <(E-Mail Removed)>, Gilles Ganault wrote:

>I'm running Ubuntu 7.04 Server to which I need to add e-mail
>capability. I installed Postfix through "apt-get install postfix",
>edited /etc/postfix/main.cf.


I don't use Postfix, but did you also edit /etc/postfix/aliases and
run 'postalias' to make the changes effective?

>Since I couldn't figure out how to use the sendmail command


Yes - 'sendmail' is a Mail Transfer Agent, just as Postfix, Qmail,
and EXIM. Sendmail is not for _creating_ mail, or _reading_ mail.
For that, you want any of the dozens of Mail User Agents -
'usr/bin/mail' being one of many.

>I installed mailutils... but failed finding examples on how to use
>/usr/bin/mail with all the fields set from the command line:


Yeah, '/usr/bin/mail' is an ancient, crude tool for creating and
reading mail. It's not set up to forge usernames, so mucking with
the headers isn't going to do much.

>echo "Call from customer X" | mail -s "Call from customer X" -f
>(E-Mail Removed) (E-Mail Removed):


Nope.

>ubuntu postfix/smtp[10213]: D24476343E1: to=<(E-Mail Removed)>,
>relay=smtp.isp.tld [some_ip_here]:25, delay=0.37,
>delays=0.08/0.04/0.22/0.03, dsn=5.0.0, dUmMy=bounced (host
>smtp.isp.tld[some_ip_here] said: 504 <root@acme>: Sender address
>rejected: need fully-qualified address (in reply to MAIL FROM
>command))


DO NOT USE THE ROOT ACCOUNT FOR ORDINARY TASKS.

1. The root account is for maintenance and administration.
2. Many mail server won't accept mail from 'root', knowing it to be
either forged or spam.
3. The remote mail server is complaining about mail from 'root@acme'
saying that 'acme' is not a domain. However, 'acme.com' is a
registered address (registered in California in 1991) and you are
not likely to have permission to use that.
4. Trying to send mail to Internet mail servers _OTHER THAN YOUR ISP_
using a bogus domain name will often get your mail rejected (or
worse, reported as spam) by those servers.

>Is it possible to specify the FROM


Generally speaking - no. Most mail tools only send mail as the username
that is running the mail user agent. You can send files directly to the
Mail Transport Agent (EXIM, postfix, qmail, sendmail), but they may not
accept it, or may include warnings that the mail is bogus. Likewise,
the remote mail server may reject the mail, based on a number of mail
blocklists.

>and TO fields from the command line


You've already got the 'To' field set, so that's not your problem.

>and if yes, how?


Run the mail creation program as a valid user so that you don't have
to fake the sender information.

Old guy
 
Reply With Quote
 
Bit Twister
Guest
Posts: n/a

 
      11-13-2007, 08:45 PM
On Tue, 13 Nov 2007 03:25:22 +0100, Gilles Ganault wrote:
> Hello
>
> I'm running Ubuntu 7.04 Server to which I need to add e-mail
> capability. I installed Postfix through "apt-get install postfix",
> edited /etc/postfix/main.cf.


Can we assume you have this line in main.cf
masquerade_exceptions = root

That will help keeping root's mail on your LAN
instead of escaping onto the Internet.

Can we also assume you modified aliases's file about/around the 11'th
line from the bottom, to a user fred, done a
postalias aliases
postfix stop
cp /dev/null mail logs (errors, warnings, info) in /var/log/mail/ (guessing)
postfix start
and cat those same files to check for errors.

Then logged in to the fred user account, set up thunderbird or some email
client in/out server to be the Fully Qualified Domain Name (FQDN) of your
node, and sent/received message from fred.

If all the above worked, I would assume fred could click up a terminal and
doing a

mail -s "Subject text here" $USER < /etc/profile
would cause fred to have /etc/profile in his mail client's mail inbox.

If so, check your aliases change by doing a
mail -s "Subject text here" root < /etc/profile
and see if fred gets a repeat email except it will be from root.

Now you know your MTA (postfix) is working on the LAN.

> ubuntu postfix/smtp[10213]: D24476343E1: to=<(E-Mail Removed)>,
> relay=smtp.isp.tld [some_ip_here]:25, delay=0.37,
> delays=0.08/0.04/0.22/0.03, dsn=5.0.0, dUmMy=bounced (host
> smtp.isp.tld[some_ip_here] said: 504 <root@acme>: Sender address
> rejected: need fully-qualified address (in reply to MAIL FROM
> command))
>
> Is it possible to specify the FROM and TO fields from the command
> line, and if yes, how?


Yes but you have no reason to be dinking with those lines unless you
are a spammer.
Or your isp requires your email header to be from it's domain when
connecting to it's smtp server.

Usual problem is you have not given your node a FQDN.
If node name is darkstar.acme then there is the bad domain name for
the node darkstar.

Let's assume your ip address is 82.237.75.54 for your node. And you
tacked on .com to careate a FQDN so node name is now darkstar.acme.com

That is bad because
$ host acme.com
shows
acme.com has address 216.27.178.28
acme.com mail is handled by 10 smtp-b.acme.com.
acme.com mail is handled by 10 smtp-c.acme.com.

and acme.com sys admin or (E-Mail Removed) will not be happy with getting
fred email.

I recommend use someting like darkstar.acme.invalid so you have a
FQDN for your node darkstar, and mail can route around on your LAN for the
acme.invalid domain.

..invalid is a fine suffix for an unregistered/madeup domain name.

The next part of your mail problem is you do someting like
mail -s "Thanks Bit" (E-Mail Removed) < /dev/null

Assuming you have set relayhost = smtp.proxad.net or some such value.,
I would receive A

Subject: Thanks Bit
From: Fred Ganault

and if I replied to it, my MTA would try to send it to
(E-Mail Removed)lid

Several solutions.
1 You create a fred account at proxad.net
You use /etc/postfix/generic to change
acme.invalid to proxad.net
did a
postfix generic
added smtp_generic_maps = hash:/etc/postfix/generic to main.cf
postfix stop
cp /dev/null mail logs (errors, warnings, info) in /var/log/mail/ (guessing)
postfix start
and check those same files for errors.

the next
mail -s "Thanks Bit" (E-Mail Removed) < /dev/null
from fred's terminal
would give the same message except the mail header from: would contain
(E-Mail Removed)

Downside there,
Fred has to log into proxad.net to get see the mail.
all mail leaving darkstar has a return address of (E-Mail Removed)

2 Use canonical_sender,virtual (my solution)

cp canonical canonical_sender
to munge the from header into a hotmail acount
There you can set
(E-Mail Removed)lid (E-Mail Removed)
postmap canonical canonical_sender
You setup virtual for LAN users
(E-Mail Removed)lid fred
postmap virtual
postfix stop/start

Now bittwister's reply would goto (E-Mail Removed)
and fred could have a cron job using
getlive to pull the hotmail.com email down into freds inbox.

If you cannot get getlive with apt-get, code can be found
http://sourceforge.net

When all else fails, there is
http://www.postfix.org
 
Reply With Quote
 
Gilles Ganault
Guest
Posts: n/a

 
      11-14-2007, 07:00 PM
On Tue, 13 Nov 2007 21:45:07 GMT, Bit Twister
<(E-Mail Removed)> wrote:
>Yes but you have no reason to be dinking with those lines unless you
>are a spammer.


Thanks guys for the help. I just needed a command-line SMTP mail
utility so that an application running on the server could e-mail
notifications.

After failing to find such thing, I figured I didn't actually need to
run an MTA on the server, and ended up running a Python script to send
the e-mail through my ISP's SMTP server.

========
#!/usr/bin/python

from email.MIMEText import MIMEText
import smtplib,sys

body='''this text will become the body of the message
Using triple-quotes you can span it easily over multiple lines.
the result of an action'''

msg = MIMEText(body)
From = "myapp@acme..com"
To = "(E-Mail Removed)"
msg['From'] = From
msg['To'] = To
msg['Subject'] = "Call from " + sys.argv[1]

server = smtplib.SMTP("smtp.isp.net")
server.sendmail(From,[To],msg.as_string())
server.quit
========

Thx again.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exec Command sending a SMS Andrea Linux Networking 3 10-28-2008 02:13 PM
Sending email Bill Ridgeway Broadband 2 07-01-2007 04:24 PM
Sending Email Not via ISP Servers Burton Bradstock Broadband 23 10-01-2006 11:32 AM
sending email steph Wireless Networks 0 06-19-2006 11:31 PM
sending of email Me Broadband 8 05-02-2004 03:18 PM



1 2 3 4 5 6 7 8 9 10 11