这段时间在学习python程序语言,发觉python确实是比较简洁的语言,完成相同的功能比JAVA用更少的代码
用python写了一个发送邮件的功能,只需要短短几行就完成了,而以前用java写,需要导入好几个jar,代码行
也比python要多,感觉用JAVA完成这些小功能就像俗话说的杀鸡用牛刀了,而python就像精准的手术刀,下面就
是邮件发送的python代码
import time
import email
import smtplib
def send_mail():
try:
handle = smtplib.SMTP('mxserver.si-tech.com.cn',25)
handle.login('libod','libo123')
msg = 'Subject:hello\r\n this is a test'
handle.sendmail( 'libod@si-tech.com.cn','libod@si-tech.com.cn',msg)
handle.close()
return 1
except Exception as e:
print('send mail error')
return 0
send_mail()
用python写了一个发送邮件的功能,只需要短短几行就完成了,而以前用java写,需要导入好几个jar,代码行
也比python要多,感觉用JAVA完成这些小功能就像俗话说的杀鸡用牛刀了,而python就像精准的手术刀,下面就
是邮件发送的python代码
import time
import email
import smtplib
def send_mail():
try:
handle = smtplib.SMTP('mxserver.si-tech.com.cn',25)
handle.login('libod','libo123')
msg = 'Subject:hello\r\n this is a test'
handle.sendmail( 'libod@si-tech.com.cn','libod@si-tech.com.cn',msg)
handle.close()
return 1
except Exception as e:
print('send mail error')
return 0
send_mail()