Email Directly from python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brad

    Email Directly from python

    I'd like to send email directly from within python without having to
    rely on an external smtp server. You know, something like the good, old
    Unix...

    echo My_message | mail -s Subject person@someplac e.com

    Can Python do something similar in a portable fashion without a smtp
    server installed on the machine?

    Thanks,
    Brad
  • Larry Bates

    #2
    Re: Email Directly from python

    brad wrote:
    I'd like to send email directly from within python without having to
    rely on an external smtp server. You know, something like the good, old
    Unix...
    >
    echo My_message | mail -s Subject person@someplac e.com
    >
    Can Python do something similar in a portable fashion without a smtp
    server installed on the machine?
    >
    Thanks,
    Brad
    smtp module can do what you want yes.

    -Larry

    Comment

    • Martin P. Hellwig

      #3
      Re: Email Directly from python

      Larry Bates wrote:
      brad wrote:
      >I'd like to send email directly from within python without having to
      >rely on an external smtp server. You know, something like the good,
      >old Unix...
      >>
      >echo My_message | mail -s Subject person@someplac e.com
      >>
      >Can Python do something similar in a portable fashion without a smtp
      >server installed on the machine?
      >>
      >Thanks,
      >Brad
      >
      smtp module can do what you want yes.
      >
      -Larry
      The tricky part is how to resolve the mail server for a mail address.
      Usually you have to query the mx record of that domain. I solved that by
      looking if I can find the nslookup binary.

      I already wrote a command line mailer that can do attachments too, no
      need to write it again. If anybody is interested I can open-source it.

      --
      mph

      Comment

      • Guilherme Polo

        #4
        Re: Email Directly from python

        2008/2/13, brad <byte8bits@gmai l.com>:
        I'd like to send email directly from within python without having to
        rely on an external smtp server. You know, something like the good, old
        Unix...
        >
        echo My_message | mail -s Subject person@someplac e.com
        I hope to not disappoint you, but mail will invoke a smtp server to
        send your mail.
        >
        Can Python do something similar in a portable fashion without a smtp
        server installed on the machine?
        You can use a smtp server that is installed somewhere else.

        --
        -- Guilherme H. Polo Goncalves

        Comment

        • brad

          #5
          Re: Email Directly from python

          Martin P. Hellwig wrote:
          The tricky part is how to resolve the mail server for a mail address.
          Usually you have to query the mx record of that domain. I solved that by
          looking if I can find the nslookup binary.
          The from and to are static constants... they don't change. Mail just
          seems so tricky these days what with all the blacklists, greylists,
          whitelists, etc. It's almost as if email is broken. Location of the
          sending pc matters too. Just wondering if there is a super simple one
          liner in Python (that's portable) that can do this.

          Comment

          • Martin P. Hellwig

            #6
            Re: Email Directly from python

            brad wrote:
            Martin P. Hellwig wrote:
            >
            >The tricky part is how to resolve the mail server for a mail address.
            >Usually you have to query the mx record of that domain. I solved that
            >by looking if I can find the nslookup binary.
            >
            The from and to are static constants... they don't change. Mail just
            seems so tricky these days what with all the blacklists, greylists,
            whitelists, etc. It's almost as if email is broken. Location of the
            sending pc matters too. Just wondering if there is a super simple one
            liner in Python (that's portable) that can do this.
            >
            Well the problem is that you can't control whether the to address won't
            be handled with a different mail server in the future. Whether the
            receiving party marks your mail as spam or not is actually their
            problem. If you act according to the RFC's it should be delivered.
            Of course it helps if you don't make the content be spam ;-)

            --
            mph

            Comment

            • Martin P. Hellwig

              #7
              Re: Email Directly from python

              Martin P. Hellwig wrote:
              <cut>
              I already wrote a command line mailer that can do attachments too, no
              need to write it again. If anybody is interested I can open-source it.
              >
              To reply on my own post ;-)
              Even if nobody is interested in case you change your mind it is hosted
              at: http://code.google.com/p/curtusmail/

              Under the new BSD license, even included a stand-alone (py2exe) windows
              version for the couple of remaining servers that have no python installed.

              The non-compiled version should work on all platforms having a
              reasonable new python version and nslookup.

              --
              mph

              Comment

              • Martin P. Hellwig

                #8
                Re: Email Directly from python

                Guilherme Polo wrote:
                <cut>
                I hope to not disappoint you, but mail will invoke a smtp server to
                send your mail.
                >
                <cut>
                I disagree. If you really want to, all you need is telnet. You connect
                to port 25 of the mail server that handles the mail of the domain for
                that mail address and do the helo, mail from, rcpt to, data stuff.

                Mail indeed does invoke a smtp server, but strictly speaking only to
                receive it for the user.

                --
                mph

                Comment

                • Martin P. Hellwig

                  #9
                  Re: Email Directly from python

                  Dennis Lee Bieber wrote:
                  <cut>
                  The first response to the query was to invoke the command line
                  "mail" utility of a Unix type OS. THAT program is, what I believe, was
                  meant by "mail will invoke a smtp server"... Not "mail" as a general
                  concept, but the utility command...
                  Ah yes I see that now, sorry for the misinterpretati on.

                  --
                  mph

                  Comment

                  • Daniel Folkes

                    #10
                    Re: Email Directly from python

                    You could always just set up a gmail account and use that SMTP. Thats
                    what I do. Then all you have to do is google search for "gmail smtp
                    python" and get some easy code.

                    You can even send attatchments really easy.

                    -Daniel Folkes

                    brad wrote:
                    I'd like to send email directly from within python without having to
                    rely on an external smtp server. You know, something like the good, old
                    Unix...
                    >
                    echo My_message | mail -s Subject person@someplac e.com
                    >
                    Can Python do something similar in a portable fashion without a smtp
                    server installed on the machine?
                    >
                    Thanks,
                    Brad

                    Comment

                    Working...