send email

Discussion in 'Python' started by Alberto Vera, Sep 25, 2003.

  1. Alberto Vera

    Alberto Vera Guest

    Hello:

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

    Thanks
    Alberto Vera, Sep 25, 2003
    #1
    1. Advertising

  2. =?ISO-8859-1?Q?David_Asorey_=C1lvarez?=, Sep 25, 2003
    #2
    1. Advertising

  3. 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<>"
    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
    Felix McAllister, Sep 25, 2003
    #3
  4. Alberto Vera wrote:
    > Hello:
    >
    > Could you tell me How I can send an email using WIN2000? What do I need?
    >
    > Thanks


    Why don't you try the following:

    ##### start of script #######
    from email.MIMEText import MIMEText
    import smtplib

    myVar = 'result of previous action'

    body='''this text will become the body of the message
    Using triple-quotes you can span it easily over multiple lines.
    You can also add the value of variables in it: %s .
    This can come in handy if you want to mail
    the result of an action''' % (myVar)

    msg = MIMEText(body)
    From = ""
    To = ""
    CC = ""
    msg['From'] = From
    msg['To'] = To
    msg['Cc'] = CC
    msg['Subject'] = "Don't leave me empty please"

    server = smtplib.SMTP("mailserver.mydomain.org")
    server.sendmail(From,[To,CC],msg.as_string())
    server.quit

    ###### end of script #####
    Rudy Schockaert, Sep 25, 2003
    #4
    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. Peter
    Replies:
    0
    Views:
    3,355
    Peter
    Jul 1, 2003
  2. Replies:
    2
    Views:
    395
    Tintin
    Jan 5, 2007
  3. Replies:
    13
    Views:
    464
    Randy Webb
    May 14, 2006
  4. pbd22
    Replies:
    1
    Views:
    147
  5. ashish makani
    Replies:
    5
    Views:
    573
    Mark Lawrence
    Sep 20, 2012
Loading...

Share This Page