Send mail for the IBM supervessel power cloud platform, supervesselsend

Source: Internet
Author: User

Send mail for the IBM supervessel power cloud platform, supervesselsend

Disclaimer: This document is only intended for learning and communication purposes and cannot be used for other commercial purposes.
Author: Chaoyang _ tony
E-mail: linzhaolover@163.com
Create Date: 2015-3-9 22:55:43 Monday
Last Change: 22:55:52 Monday
Reprinted please indicate the source: http://blog.csdn.net/linzhaolover

Abstract:
Chao Di, we have a new task today. We will run a test instance on your machine and mail the result to my mailbox for future reference! First, it is sent in text mode. Later, it is changed to html format to improve the appearance.

Program running platform

IBM supervessel power cloud platform https://ptopenlab.com/cloudlab/index.html

Test to obtain ifconfig Information
opuser@gto:~/Smail$ ifconfig >  ifconfig_info.txtopuser@gto:~/Smail$ cat ifconfig_info.txteth0      Link encap:Ethernet  HWaddr fa:16:3e:2f:e6:63          inet addr:10.10.1.29  Bcast:10.10.1.255  Mask:255.255.255.0          inet6 addr: fe80::f816:3eff:fe2f:e663/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1454  Metric:1          RX packets:33241 errors:0 dropped:0 overruns:0 frame:0          TX packets:19081 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000          RX bytes:7482632 (7.4 MB)  TX bytes:4848283 (4.8 MB)lo        Link encap:Local Loopback          inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host          UP LOOPBACK RUNNING  MTU:65536  Metric:1          RX packets:10 errors:0 dropped:0 overruns:0 frame:0          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0          RX bytes:954 (954.0 B)  TX bytes:954 (954.0 B)

If the test result is available, the result is sent to my mail.

#!/usr/bin/env python# -*- coding:UTF-8 -*-import sys, os, string, timeimport smtplib,base64, StringIOfrom email.MIMEMultipart import MIMEMultipartfrom email.MIMEText import MIMETextfrom email.Utils import COMMASPACE, formatdatefrom email import Encodersdef send_mail(send_from, send_to,subject, text,          server="localhost", user = None, password = None):    assert type(send_to)==list    msg = MIMEMultipart()    msg['From'] = send_from    msg['To'] = COMMASPACE.join(send_to)    msg['Date'] = formatdate(localtime=True)    msg['Subject'] = subject    msg.attach( MIMEText(text) )    try:        #smtp = smtplib.SMTP(server)        smtp = smtplib.SMTP_SSL(server)        if (user != None):          smtp.ehlo()          smtp_userid64 = base64.encodestring(user)          smtp.docmd("auth", "login " + smtp_userid64[:-1])          if password != None:            smtp_pass64 = base64.encodestring(password)            smtp.docmd(smtp_pass64[:-1])        smtp.sendmail(send_from, send_to, msg.as_string())        smtp.quit()        print "Send Ok"    except Exception as e:        print "send maill error", e### set mail server config### 465 is open ssl port mail_server='smtp.163.com:465'CODEC = 'utf-8'mail_subject='Test result report mail'### read test result information, add to mail , use 'utf-8' encodertext='This is my first mail , for ifconfig infomations!'fp=open('ifconfig_info.txt','r')text=text+'\n'+fp.read()mailtext=text.decode(CODEC)fp.close()mail_from='myaccount@163.com'user='myaccount'passwd='mypassword'send_to=['zhaoyang_tony@163.com']send_mail(mail_from, send_to, mail_subject, mailtext,          mail_server,user ,passwd )print 'Done'

Note:465 is the encrypted port of the mail server, which is usually relatively secure. Of course, you can also replace the unencrypted port 25, but use smtp = smtplib. SMTP (server) comment out the encrypted line below # smtp = smtplib. SMTP_SSL (server ).

The mail content is the content of the file that is directly read through read and then sent through UTF-8 encoding. Later, we will consider modifying it to the html format to make it more beautiful,

Run demo
opuser@gto:~/Smail$ python Smail.pySend OkDone
Images and truth

Summary:Receive email from the boss

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.