Trying to utilize mailx to send mail via apython script

Discussion in 'Linux Networking' started by Ferrous Cranus, Sep 5, 2013.

  1. Στις 8/9/2013 5:11 μμ, ο/η Jonathan N. Little έγÏαψε:

    i use CentOS 6.4 and yum install ssmtp cannot detect it.

    Please if you comment in for my other questions too.
     
    Ferrous Cranus, Sep 8, 2013
    #21
    1. Advertisements

  2. Ferrous Cranus

    David Brown Guest

    I have no experience with GMail, but there you can put whatever you want
    in the sender field (or any other field) when you connect to an SMTP
    server. And the SMTP server can always choose to override fields with
    its own settings if it wants. This applies equally to when you are
    using Python's SMTP module to connect to the GMail server, or when you
    send first to one SMTP server and relay on to GMail.

    Since Python's SMTP module "speaks" SMTP to gmail, and any other mail
    program or MTA that will send mail via a gmail relay also "speaks" SMTP
    for that transfer, I would be very surprised if there is some effect you
    can get with an additional program or relay that you cannot get by using
    Python directly.

    Your ISP should also have an SMTP server that you can connect to in the
    same way (via Python), and send it on that way.
     
    David Brown, Sep 8, 2013
    #22
    1. Advertisements

  3. Ferrous Cranus

    David Brown Guest

    If I understand you correctly here, you want a visitor to be able to put
    a "To" address and a "From" address, and you want to pass on the mail
    with those addresses and no others.

    Let me know if you get it working - I'll sell the website's address to
    spammers for a substantial fee.


    Put another way, do /not/ do this. If you are sending email, then /you/
    are sending it. If /your/ server is sending email, then the "from" and
    "sender" addresses should be /your/ server or related email addresses.
    It is basically fraud to say that someone else sent the email, even if
    that someone had filled in the web form for the email.

    Most SMTP clients - ssmtp, Python's SMTP module, or anything else other
    than a standard email program (which tend to be a bit limited) can put
    anything you want in any field.
     
    David Brown, Sep 8, 2013
    #23
  4. Στις 8/9/2013 5:34 μμ, ο/η David Brown έγÏαψε:
    If i setup some mail server on localhost can i alter the from field to
    the one i want and suppress the hostname of the server?

    Thai is what i want to know.

    GMail doesnt care what you tell it to be the FROM field, it always ads
    up an authenticated Sender address into the headers and also display the
    hostname used to directly connect to it.
     
    Ferrous Cranus, Sep 8, 2013
    #24
  5. Στις 8/9/2013 5:42 μμ, ο/η David Brown έγÏαψε:

    No it is not.

    My web form at http://superhost.gr ask the visitor for his mail address
    and asks him for the subject to.

    I want those the visitor used to be seen as FROM and MESSAGE and not my
    gmail addres as sender.

    Is there a way to make this work?
     
    Ferrous Cranus, Sep 8, 2013
    #25
  6. Ferrous Cranus

    Whiskers Guest

    If you use the Gmail SMTP server to deliver an email, you cannot stop
    Google from adding whatever header information they want.

    Google may well object to your Gmail account being used to send emails
    not coming from you, indeed they should reject any such email - and
    terminate your Gmail account if it happens more than a few times. The
    only exception may be that Google will let you 'register' particular
    email addresses which are not provided by them, so that you can send
    messages 'from' those addresses using their server; I don't know if
    Google charge extra for that service. The headers available to the
    recipient will show that Gmail have 'relayed' the message, and will show
    the public IP number of the internet connection used for initiating the
    email, and whatever hostname your system identifies itself with when
    logging in to the Gmail server.

    If your visitors have email addresses of their own already, why not let
    them log in to their own email accounts instead of trying to use your
    Gmail account?
     
    Whiskers, Sep 8, 2013
    #26
  7. Ferrous Cranus

    Todd Guest

    `dnsdomainname` gives you both your hostname and your domain
    name. Try just running the command by itself from the command
    line.

    Note sure what you mean by "visitor used". Is the visitor's
    address what you want to use as "From:"? If so, it needs to
    be a gMail account and you need to use his info in
    "from=", "smtp-auth-user=", and "smtp-auth-password=".

    If "visitor" is not a gMail account, you need to find out
    what the SMTP settings are for his account.

    Not sure what is going on. Here is a scatter gun approach.

    1) is "mailx" install and at the latest version? From
    the command line, run the following to see if it
    is there and in your path:
    which mailx

    2) try putting "./" in front of the MailXTest.gmail.
    ./MailXTest.gmail

    3) "from=" and "smtp-auth-user=" should be the same
    thing ().

    4) try adding tracing to the script. On line one, add "-x"
    #!/bin/bash -x
    if there is a problem, it will show you where

    -T
     
    Todd, Sep 8, 2013
    #27
  8. Ferrous Cranus

    David Brown Guest

    One last time - you can do /exactly/ the same thing from Python.

    <http://docs.python.org/2/library/smtplib.html#smtp-example>

    And again, /don't/ do this with other people's email addresses. Unless
    you are specifically making a website with this intention (i.e., a
    web-based email client), then this is verging on fraud. It is certainly
    not what users would expect or like.
     
    David Brown, Sep 9, 2013
    #28
  9. Ferrous Cranus

    Todd Guest


    $ cat /etc/redhat-release
    Scientific Linux release 6.4 (Carbon)

    $ yum --enablerepo=* whatprovides ssmtpssmtp-2.61-19.el6.x86_64 :
    Extremely simple MTA to get mail off the system to a Mailhub
    Repo : epel



    ....
     
    Todd, Sep 9, 2013
    #29
  10. Ferrous Cranus

    Todd Guest


    You can download this from pbone.net, if you don't want to
    get install EPEL repo.

    Also, I never got ssmtp to work with gmail.

    -T
     
    Todd, Sep 9, 2013
    #30
  11. Στις 8/9/2013 7:56 μμ, ο/η Whiskers έγÏαψε:
    What do you mean by Google letting me 'register' some mail address?
    I dont unserstand that sentence.

    Will it still add up Sender Header of it own?
     
    Ferrous Cranus, Sep 9, 2013
    #31
  12. Στις 8/9/2013 11:15 μμ, ο/η Todd έγÏαψε:
    [~]# ./MailXTest.gmail
    Send options without primary recipient specified.
    Usage: mailx -eiIUdEFntBDNHRV~ -T FILE -u USER -h hops -r address -s
    SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users
    ../MailXTest.gmail: line 4: -S: command not found
    [~]# cat MailXTest.gmail
    #!/bin/bash -x
    #
    echo "mailx test" | mailx -v -s `dnsdomainname`" gmail smtp test subject" \
    -S smtp-use-starttls \
    -S ssl-verify=ignore \
    -S smtp-auth=login \
    -S smtp=smtp://smtp.gmail.com:587 \
    -S from= \
    -S smtp-auth-user= \
    -S smtp-auth-password="pass" \
    -S nss-config-dir=/home/nikos/certs/ \


    The visitor of http://superhost.gr tried to send me an email using the
    wb gorm i ahve which asks for his mail address and MESSAGE he wans to
    send me.

    i have no way of knowing the smtp settings the visitor uses or even if
    his mail address is real but no matter what, the the FROM field must
    contain the mail address the user types in the web form.
     
    Ferrous Cranus, Sep 9, 2013
    #32
  13. Ferrous Cranus

    Todd Guest

    You should create a special eMail address of your own for
    these messages and use that to send with. "Supposedly"
    (note the weasel word), "-S from=" and "-S smtp-auth-user="
    can be different.
     
    Todd, Sep 9, 2013
    #33
  14. Ferrous Cranus

    Jorgen Grahn Guest

    .
    You've mentioned this several times. What's the problem? It seems like
    a sane and sensible thing for GMail to do, and also a harmless one.
    RFC 2822 indicates Sender: and From: can be seen as "the guy who sent
    the message; pressed the button" and "the guy who wrote it and is
    responsible for it".

    And doesn't that describe what you're aiming for?

    The originator fields of a message consist of the from field, the
    sender field (when applicable), and optionally the reply-to field.
    ... If the from field contains more than one mailbox specification
    in the mailbox-list, then the sender field ... MUST appear in the
    message. In either case, an optional reply-to field MAY also be
    included ...

    The originator fields indicate the mailbox(es) of the source of the
    message. The "From:" field specifies the author(s) of the message,
    that is, the mailbox(es) of the person(s) or system(s) responsible
    for the writing of the message. The "Sender:" field specifies the
    mailbox of the agent responsible for the actual transmission of the
    message. For example, if a secretary were to send a message for
    another person, the mailbox of the secretary would appear in the
    "Sender:" field and the mailbox of the actual author would appear in
    the "From:" field. ...

    The originator fields also provide the information required when
    replying to a message. When the "Reply-To:" field is present, it
    indicates the mailbox(es) to which the author of the message suggests
    that replies be sent. In the absence of the "Reply-To:" field,
    replies SHOULD by default be sent to the mailbox(es) specified in the
    "From:" field unless otherwise specified by the person composing the
    reply.

    This part is also nice:

    In all cases, the "From:" field SHOULD NOT contain any mailbox that
    does not belong to the author(s) of the message.

    /Jorgen
     
    Jorgen Grahn, Sep 9, 2013
    #34
  15. Ferrous Cranus

    Whiskers Guest

    Go to <https://support.google.com/mail/answer/22370?hl=en-GB&ctx=mail>
    "Sending mail from a different address".

    ,----
    | Gmail lets you send messages with another of your email addresses listed
    | as the sender instead of your Gmail address. This feature helps you
    | manage multiple accounts from the Gmail interface; it works only if you
    | already own the email account linked to the alternate address. [...]
    `----
    I wouldn't be at all surprised. If you don't want Google to 'stamp'
    your mail, don't send it using Google.
     
    Whiskers, Sep 9, 2013
    #35
  16. Ferrous Cranus

    Whiskers Guest

    That's fine, but only while the email is on your own system. If you
    want users of your system to be able to send local emails to you and
    other local users, each user should have a username of their own which
    they use to log in to your system, and the computer they use will have a
    hostname; those two things combine to create email addresses that are
    valid for use within your own system - "[email protected]" or
    "" or "" or whatever. This sort
    of arrangement is not usually worth the bother, apart from getting
    system status and error reports sent to the system administrator by the
    various 'daemons' or 'services' you have running.

    If you want to allow visitors to access their existing Gmail accounts
    from your computer, just set up a limited user called (for example)
    guest, with access only to a web browser - possibly in 'kiosk mode' - so
    that they can log in using the same login details as they do from
    anywhere else.

    Or are you trying to become an email service provider yourself?
     
    Whiskers, Sep 9, 2013
    #36
  17. Really? I usually use nullmailer but it does not work with gmail.
    ssmtp was the only thing that I got to work with gmail on several
    computers. Generally what I do to assist in remote administration for
    servers. I create a gmail account for error messages and notices, use
    ssmtp to setup a lightweight smtp "server" My scripts email warnings,
    errors, and messages to that account and the server admins only have to
    monitor that email account from anywhere...
     
    Jonathan N. Little, Sep 9, 2013
    #37
  18. It sounds more like the OP is trying to setup form to mail and wishes to
    validate if the visitor's supplied email address in his form is valid.
    Well, there is no real way to do this one shot. If he is using that form
    to create a auto-reply with that user supplied address he better take
    measures to prevent robo comment spam.
     
    Jonathan N. Little, Sep 9, 2013
    #38
  19. Ferrous Cranus

    Todd Guest

    It took me several days to figure out how to get mailx to
    work with gmail and zmail. I was pretty frazzled by
    the end of it. Probably contributed with me not getting
    ssmtp working
     
    Todd, Sep 9, 2013
    #39
  20. Other than installing it edit the /etc/ssmtp/ssmtp.conf to something
    like this change what is obvious:

    # /etc/ssmtp/ssmtp.conf
    # Sample Config file for sSMTP sendmail
    #
    # The person who gets all mail for userids < 1000
    root=
    UseTLS=YES
    UseSTARTTLS=YES
    mailhub=smtp.gmail.com:587
    # Are users allowed to set their own From: address?
    # YES - Allow the user to specify their own From: address
    # NO - Use the system generated From: address
    FromLineOverride=YES
    #
    # Username and password for Google's Gmail servers
    # From addresses are settled by Mutt's rc file, so
    # with this setup one can still achieve multi-user SMTP
    AuthUser=
    AuthPass=YOUR_GMAIL_PASSWORD

    Then you might like to setup alias like as follows:

    #/etc/ssmtp/revaliases
    # sSMTP aliases
    #
    # Format: local_account:eek:utgoing_address:mailhub
    #
    # Some common handy examples to redirect system script messages
    root:
    postmaster:


    And you can test it out with the bash one-liner

    echo -e "TO: Admin <>\nFROM: test
    <[email protected]>\nSUBJECT: A Test\nA sample message" | $(which sendmail)
     
    Jonathan N. Little, Sep 9, 2013
    #40
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.