Send mail for IBM Supervessel Power Cloud Platform

Source: Internet
Author: User

Disclaimer: This document is only used for learning and communication purposes and should not be used for any other commercial purpose
Author: Chaoyang _tony
e-mail: [Email protected]
Create date:2015-3-9 22:55:43 Monday
Last change:2015-3-9 22:55:52 Monday
Reprint Please specify source: Http://blog.csdn.net/linzhaolover

Summary:
Chaodi, we have a new task today, run a test instance on your machine, then send the result via mail to my mailbox, convenient for later review! First sent through text mode, later changed to HTML format, increase the aesthetics.

Program Run Platform

IBM Supervessel Power Cloud Platform https://ptopenlab.com/cloudlab/index.html

Test get ifconfig Information
Opuser@gto: ~/smail$ Ifconfig > Ifconfig_info.txtopuser@gto: ~/smail$ Cat Ifconfig_info.txteth0      Link EnCap:Ethernet  HWaddr fa: -:3e:2F:e6: theinetAddr:10.10.1.29  Bcast:10.10.1.255  Mask:255.255.255.0Inet6Addr: FE80:: f816:3eff:fe2f:e663/ - 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: +          RX bytes:7482632(7.4 MB)TX bytes:4848283(4.8 MB) LoLink EnCap:Local LoopbackinetAddr:127.0.0.1  Mask:255.0.0.0Inet6Addr: ::1/ - Scope: Host           up LOOPBACK RUNNING  MTU:65536  Metric:1          RX Packets:Ten Errors:0 dropped:0 Overruns:0 Frame:0          TX Packets:Ten Errors:0 dropped:0 Overruns:0 Carrier:0          Collisions:0 Txqueuelen:0          RX bytes:954(954.0 B)TX bytes:954(954.0 B)

The test results are there, so the next step is to send the results to my mail.

#!/usr/bin/env python#-*-Coding:utf-8-*-ImportSYS, OS, string, timeImportSmtplib,base64, Stringio fromEmail. MimemultipartImportMimemultipart fromEmail. MimetextImportMimetext fromEmail. UtilsImportCommaspace, FormatDate fromEmailImportEncoders def send_mail(Send_from, Send_to,subject, text, server="localhost", user = Non E, password = None):    assertType (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])ifPassword! =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"    exceptException asE:Print "Send maill Error"E# # # set mail server config# # # 465 is open SSL portMail_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 was 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=' [email protected] 'User=' MyAccount 'Passwd=' MyPassword 'send_to=[' [email protected] ']send_mail (Mail_from, send_to, Mail_subject, Mailtext, Mail_server,user, passwd)Print ' Done '

Note: 465 is the mail server encryption port, usually use this relatively secure some, of course you can also change to non-encrypted port 25, but at this time to use SMTP = Smtplib. SMTP (server) commented out the following encrypted line #smtp = Smtplib. Smtp_ssl (server).

Mail content is read directly through the contents of the file, and then sent through the Utf-8 encoding of the message content, later will be considered to modify the HTML format, will be more beautiful,

Run Demo
opuser@gto:~/Smail$ Smail.pySendOkDone
There's a picture of the truth

Summary: the boss received the mail

Send mail for IBM Supervessel Power Cloud Platform

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.