send email

A

Alberto Vera

Hello:

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

Thanks
 
F

Felix McAllister

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<[email protected]>"
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.
 
R

Rudy Schockaert

Alberto said:
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 = "(e-mail address removed)"
To = "(e-mail address removed)"
CC = "(e-mail address removed)"
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 #####
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top