Raspberry Pi Combat 2: Send IP address to your own mailbox

Source: Internet
Author: User
Tags email account

Pick UP:


2.
Program to send mail:
There are many ways to send e-mails via web.py's own library.
Configure Python +web.py First
Enter Python in the shell
If the Python 2.7.3 is displayed, the open Python2 succeeds (if you want to exit, CTRL + Z)
Continue entering the import web
If Importerror:no module named XXX, the web.py is not installed
If you do not have an error, you have installed web.py
Install web.py as follows
Enter wget http://webpy.org/static/web.py-0.37.tar.gz in the shell
Then TAR-XF web.py-0.37.tar.gz.
Then sudo python setup.py install
Try the import Web again, and if you do not make an error, the installation succeeds
3.
Send IP-to-mailbox program implementations:
In the terminal nano mail.py, and then write these content, configure their own account password, if the error, may be the cause of program indentation
#!\usr\bin\env python
#encoding: Utf-8
Import Web
#程序通过直接调用web. PY Library to implement e-mail
#cc, the BCC uses the default parameters
def send_mail (send_to, subject, body, Cc=none, Bcc=none):
Try
Web.config.smtp_server = ' smtp.163.com ' # #邮件发送服务器
Web.config.smtp_port = # #不设置将使用默认端口
Web.config.smtp_username = ' Your mailbox user name, no @xx.com ' # #邮件服务器的登录名
Web.config.smtp_password = ' Password of your mailbox ' # #邮件服务器的登录密码
Web.config.smtp_starttls = True
Send_from = ' Your email account, [email protected] ' # #发送的邮件
Web.sendmail (Send_from, send_to, subject, body, CC=CC, BCC=BCC)
Return 1 #pass
Except Exception, E:
Print E
Return-1 #fail

If __name__== ' __main__ ':
send_to = [' Send to who ']
Subject = ' message header '
BODY = ' e-mail content \ Try It '
CC = [' cc to who '] # #抄送
BCC = [' secret sent to who '] # #密抄
Send_mail (send_to, subject, Body, CC, BCC)
After the configuration is complete, Python mail.py this time your mailbox is successfully sent
Where: Body is what you write in the letter
Note: Program calls Web.sendmail slower, estimated at around 2s.
Here is my mail.py:
#!\usr\bin\env python
#encoding: Utf-8
Import Web
def send_mail (send_to, subject, body, Cc=none, Bcc=none):
Try
Web.config.smtp_server = ' smtp.163.com ' # #邮件发送服务器
Web.config.smtp_port = # #不设置将使用默认端口
Web.config.smtp_username = ' xxxx ' # #邮件服务器的登录名
Web.config.smtp_password = ' xxxx ' # #邮件服务器的登录密码
Web.config.smtp_starttls = True
Send_from = ' [email protected] ' # #发送的邮件

Web.sendmail (Send_from, send_to, subject, body, CC=CC, BCC=BCC)
Return 1 #pass
Except Exception, E:
Print E
Return-1 #fail
If __name__== ' __main__ ':
F=file ('/home/pi/desktop/ip.log ')
F1=f.read ()
F.close ()
send_to = [' [email protected] ']
Subject = ' Connection check '
BODY = ' Hello, xxxx! I am still alive. I'll send you a email in another hour. ', F1
Send_mail (send_to, subject, body)
The effect at this point:
You have received your Raspberry Pi network and extranet IP!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Raspberry Pi Combat 2: Send IP address to your own mailbox

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.