Python Road "third": Python Basics (13)--function general parameters

Source: Internet
Author: User

# General Parameters: in strict accordance with the smooth, the actual parameters are assigned to the formal parameters

# def send (name):
# ...
# Send ("Eric")


def sendmail (MAIL_ADDR):#第一步, create function (MAIL_ADDR is formal parameter) step three, mail_addr = {str} ' [email protected] '
Try# This feature captures anomalies and is not yet learned.
Import Smtplib
From Email.mime.textImport Mimetext
From Email.utilsImport formataddr

msg = Mimetext (' Mail content ',' Plain ',' Utf-8 ')
msg[' from '] = FORMATADDR (["Futian",' [email protected] ')
msg[' to '] = FORMATADDR (["Leave",' [email protected] ')
msg[' Subject '] =Topic

Server = Smtplib. SMTP ("Smtp.163.com",25)
Server.login ("[Email protected]","521why,.")
Server.sendmail (' [email protected] ', [Mail_addr,], msg.as_string ())#将收件人地址 ' [email protected] ' change to a variable
Server.quit ()
Except#只要try下面的代码, catch the exception and execute the code inside the except.
#发送失败执行
# return False #以上代码执行失败, returns a false
Return"No"#返回的也可以是字符串
Else
#发送成功执行
# return True #否则, returns a true
Return"Yes"#return返回值给函数调用者sendmail,



# SendMail ()
# ret = sendmail (' [email protected] ') #第二步, call function (' [email protected] ' is the actual parameter)
# ret = SendMail ("[email protected]")
# Print (ret)
# if Ret = = True: #通过判断ret是False还是True来显示发送状态
# # if Ret = = "CC": #也可以判断返回的是不是定义的字符串值
# print ("Send Success")
# Else:
# print ("Send Failed")

while True:
em = input ( "Please enter your email address:")
# sendmail (EM)
result = SendMail (em) #em是参数传递的内容, can be multiple
# Print (result)
if result = = " Yes ":
print (" sent successfully ")
else:
print ( "send Failed")

Python path "third": Python Basics (13)--function general parameters

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.