Constructing RFC2822 Message

Narendra narendra.amirinenis at gmail.com
Mon Dec 5 09:27:44 EST 2005


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




More information about the Python-list mailing list