SMTP host name

mail01

Examples (Python)

SMS sending

import smtplib
smtpserver = 'mail01'

RECIPIENTS = ['4176487xxx@mail2sms.cern.ch']
SENDER = 'firstname.lastname@cern.ch'
mssg = 'Hello world'

session = smtplib.SMTP(smtpserver)
smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)

if smtpresult:
    errstr = ""
    for recip in smtpresult.keys():
        errstr = """Could not delivery mail to: %s

Server said: %s
%s

%s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
    raise smtplib.SMTPException, errstr

File attachement

import sys, smtplib, MimeWriter, base64, StringIO

message = StringIO.StringIO()
writer = MimeWriter.MimeWriter(message)
writer.addheader('Subject', 'Test message')
writer.startmultipartbody('mixed')

# start off with a text/plain part
part = writer.nextpart()
body = part.startbody('text/plain')
body.write('This is a test, enjoy :)')

# now add an image part
#part = writer.nextpart()
#part.addheader('Content-Transfer-Encoding', 'base64')
#body = part.startbody('image/jpeg')
#base64.encode(open('kitten.jpg', 'rb'), body)

# finish off
writer.lastpart()

# send the mail
smtp = smtplib.SMTP('mail01')
smtp.set_debuglevel(1)
smtp.sendmail('from@cern.ch', 'to@cern.ch', message.getvalue())
smtp.quit()

-- SashaMazurov - 27 Sep 2007

Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2007-09-27 - SashaMazurov
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    LHCb All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback