Sending email from command line? - Networking

This is a discussion on Sending email from command line? - Networking ; 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 ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Sending email from command line?

  1. Sending email from command line?

    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
    postfix@acme.com fred@acme.com:

    ubuntu postfix/smtp[10213]: D24476343E1: to=,
    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 : 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.

  2. Re: Sending email from command line?

    > echo "Call from customer X" | mail -s "Call from customer X" -f
    > postfix@acme.com fred@acme.com:
    >
    > ubuntu postfix/smtp[10213]: D24476343E1: to=,
    > 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 : 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.

  3. Re: Sending email from command line?

    On Mon, 12 Nov 2007 21:38:29 -0500, Allen McIntosh
    wrote:

    >> echo "Call from customer X" | mail -s "Call from customer X" -f
    >> postfix@acme.com fred@acme.com:
    >>
    >> ubuntu postfix/smtp[10213]: D24476343E1: to=,
    >> 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 : 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: your@email.address
    Subject: How to send email
    To: Recipient@example.com

    This is the message'

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


  4. Re: Sending email from command line?

    On Tue, 13 Nov 2007, in the Usenet newsgroup comp.os.linux.networking, in
    article , 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
    >postfix@acme.com fred@acme.com:


    Nope.

    >ubuntu postfix/smtp[10213]: D24476343E1: to=,
    >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 : 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

  5. Re: Sending email from command line?

    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=,
    > 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 : 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 fred@acme.com 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" bittwister@mouse-potato.com < /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
    fred@darkstar.acme.invalid

    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" bittwister@mouse-potato.com < /dev/null
    from fred's terminal
    would give the same message except the mail header from: would contain
    fred@proxad.net

    Downside there,
    Fred has to log into proxad.net to get see the mail.
    all mail leaving darkstar has a return address of user_here@proxad.net

    2 Use canonical_sender,virtual (my solution)

    cp canonical canonical_sender
    to munge the from header into a hotmail acount
    There you can set
    fred@darkstar.acme.invalid fred@hotmail.com
    postmap canonical canonical_sender
    You setup virtual for LAN users
    fred@darkstar.acme.invalid fred
    postmap virtual
    postfix stop/start

    Now bittwister's reply would goto fred@hotmail.com
    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

  6. Re: Sending email from command line?

    On Tue, 13 Nov 2007 21:45:07 GMT, Bit Twister
    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 = "some_user@acme.comr"
    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 to Thread