send email

Felix McAllister felix_mcallister at hotmail.com
Thu Sep 25 17:36:14 CEST 2003


Your other option, assuming you don't mind Windows specific code, is to use the CDONTS COM library:

import win32com.client
def SendEmail(emailAddresses, subject, body, files):
    
    iConf = win32com.client.Dispatch("CDO.Configuration")
    Flds = iConf.Fields
    Flds("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value = "someserver"
    Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverport").Value = 25
    Flds("http://schemas.microsoft.com/cdo/configuration/sendusing").Value = 2     # cdoSendUsingPort
    # Authentication and stuff
    Flds('http://schemas.microsoft.com/cdo/configuration/smtpauthenticate').Value = 0 # No authentication
    # The following fields are only used if the previous authentication value is set to 1 or 2
#   Flds('http://schemas.microsoft.com/cdo/configuration/smtpaccountname').Value = "user"
#   Flds('http://schemas.microsoft.com/cdo/configuration/sendusername').Value = "domain\\user"
#   Flds('http://schemas.microsoft.com/cdo/configuration/sendpassword').Value = "password"
    Flds.Update()
    iMsg = win32com.client.Dispatch("CDO.Message")
    iMsg.Configuration = iConf
    iMsg.To = ";".join(emailAddresses)
    iMsg.From = "Test<test at test.com>"
    iMsg.Subject = subject
    iMsg.TextBody = body
    # The following assumes the files to be in the current directory
    for file in files:
        iMsg.AddAttachment("file:///" + os.getcwd() + "/" + file)
    iMsg.Send()

Felix.


> Hello:
>  
> Could you tell me How I can send an email using 
> WIN2000? What do I need?
>  
> Thanks




More information about the Python-list mailing list