Constructing RFC2822 Message

Discussion in 'Python' started by Narendra, Dec 5, 2005.

  1. Narendra

    Narendra Guest

    Hi All,

    This is narendra from india doing my engineering.

    i need to develop an E-mail client in python,which connects to my MTA
    on port 25 and sends email from there.

    I was able to do that but my e-mail is ending in bulk when i'm trying
    to senf to hotmail/msn.

    here im giving the code of my program.
    **********************************************************************************************
    import socket,string
    import sys
    import time
    from email import Encoders
    import email.Message
    import email.Utils
    from email.MIMEBase import MIMEBase
    from email.MIMEText import MIMEText
    # Reading IPConfig File
    clientSendingPort = 9000
    headuni = '000119-000257-454777-'
    headadd = 555650
    i = 0
    def read(infile):
    try:
    flopen = open(infile,'r')
    flines = flopen.readlines()
    flopen.close()
    return flines
    except IOError:
    print sys.exc_info()

    if len(sys.argv) != 3:
    print 'Usage: IPAuditMain.py <IPConfig File Name> <Email Address
    File Name>'
    sys.exit()
    try:
    ipConfigLines = read(sys.argv[1])
    emailAddConfigLines = read(sys.argv[2])
    print("reading is over")
    for line in ipConfigLines:
    print("hello")
    print line
    clIpAddress,injectIPAddress,extnIP,fromadd =
    string.split(line,',')
    print clIpAddress,injectIPAddress,extnIP
    print("how come")

    timestamp=time.strftime("[%y%m%d-%H%M%S]",time.localtime(time.time()))
    headerUnq = str(headuni) + timestamp
    headadd = headadd + 5;
    print headerUnq
    for recptEmailAdd in emailAddConfigLines:
    print("wt happened")
    print recptEmailAdd
    soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    print "socket created"
    soc.bind((clIpAddress,clientSendingPort))
    #print soc.recv(9867)
    print "after binding"
    soc.connect((injectIPAddress, 25)) # SMTP
    print recptEmailAdd
    i = i +1
    clientSendingPort = clientSendingPort + 1
    soc.send("mail from:"+fromadd+"\n")
    print soc.recv(9869)
    soc.send("rcpt to:"+ recptEmailAdd +"\n")
    print soc.recv(9869)
    soc.send("data\n")
    print soc.recv(9869)
    print headerUnq
    msg = MIMEBase('multipart','alternative')
    msg['X-PVIQ'] = headerUnq
    msg['Date']=email.Utils.formatdate(localtime=1)
    #msg['Return-Path'] = fromadd
    msg['Subject'] = 'Our convo zt'+extnIP
    msg['From'] = fromadd
    msg['To'] = recptEmailAdd
    msg.preamble = 'You will not see this in a MIME-aware mail
    reader.\n'
    msg.epilogue = ''
    outer = MIMEText('\nHai Bob '+
    'What are you doing?
    \n\nRegards,',_subtype='plain')
    msg.attach(outer)
    print("narendra u got here")
    soc.send(msg.as_string(0))
    print("u have sent the data ")
    soc.send("\n.\n")
    print("quit")
    print soc.recv(9869)
    clientSendingPort = clientSendingPort + 1
    soc.close()
    except IOError:
    print sys.exc_info()
    except:
    print 'Exception Found. Unable to process'
    *******************************************************************************************

    Can anyone please help me out how to fix the problem.

    Thanks,
    Narendra
    Narendra, Dec 5, 2005
    #1
    1. Advertising

  2. Narendra

    Guest

    On Mon, Dec 05, 2005 at 06:27:44AM -0800, Narendra wrote:
    > I was able to do that but my e-mail is ending in bulk when i'm trying
    > to senf to hotmail/msn.


    Perhaps this is an over-zealous filter on the hotmail/msn side, not a
    problem with Python.

    I don't know for sure, but some news stories indicate that without the
    presence of a special DNS record, microsoft treats messages as spam--
    e.g. http://news.zdnet.com/2100-1009-5758365.html

    Jeff

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.1 (GNU/Linux)

    iD8DBQFDlFI9Jd01MZaTXX0RAhhrAKCdyTqh+3Dd5ldwri/Tl/CVVI5bAACeMIOH
    Jtoahfy3PvMJnVcGd1IIGkA=
    =AD8o
    -----END PGP SIGNATURE-----
    , Dec 5, 2005
    #2
    1. Advertising

  3. Narendra

    Narendra Guest

    Thanks jep for the quick response.But when im sending with different
    program written in java i was able to send into inbox.

    So i thought problem was with the python code only.

    Narendra
    Narendra, Dec 5, 2005
    #3
  4. Narendra

    Steve Holden Guest

    Narendra wrote:
    > Thanks jep for the quick response.But when im sending with different
    > program written in java i was able to send into inbox.
    >
    > So i thought problem was with the python code only.
    >
    > Narendra
    >

    Are you sending from a Windows XP client? If so the firewall may be
    getting in your way. (It may already trust Java).

    You don't report the actual error, so it's difficult to say waht's going
    wrong.

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC www.holdenweb.com
    PyCon TX 2006 www.python.org/pycon/
    Steve Holden, Dec 5, 2005
    #4
  5. Narendra

    Narendra Guest

    Thanks Steve, No I'm not using windows XP client. I'm using linux
    client and no firewall is there

    Thanks,
    Narendra
    Narendra, Dec 19, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leo Muller
    Replies:
    2
    Views:
    436
    Paul Glavich [MVP - ASP.NET]
    Jun 16, 2004
  2. Replies:
    3
    Views:
    3,273
    isitmeorthey
    Aug 29, 2005
  3. richard
    Replies:
    2
    Views:
    467
    richard
    Jan 13, 2006
  4. Kris Kennaway
    Replies:
    2
    Views:
    365
    Kris Kennaway
    Aug 11, 2008
  5. Josselin

    RFC2822::EmailAddress

    Josselin, Jan 17, 2007, in forum: Ruby
    Replies:
    4
    Views:
    124
    Dominic Marks
    Jan 17, 2007
Loading...

Share This Page