博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python 和 Ruby 邮件发送
阅读量:4230 次
发布时间:2019-05-26

本文共 1162 字,大约阅读时间需要 3 分钟。

为了方便,我这儿是自己给自己发的邮件,如果条件允许,你可以用不同的邮件地址来发件和收件。

Python

# Python3import smtplibfrom email.mime.text import MIMETextfrom email.header import Header# 第三方 SMTP 服务mail_host = "smtp.qq.com"  # 设置服务器mail_user = "2392863668@qq.com"  # 用户名mail_pass = "****************"  # 口令sender = '2392863668@qq.com'receivers = ['2392863668@qq.com']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱message = MIMEText('Python 邮件发送测试...', 'plain', 'utf-8')message['From'] = Header("Looking", 'utf-8')message['To'] = Header("you", 'utf-8')subject = 'Python SMTP 邮件测试'message['Subject'] = Header(subject, 'utf-8')smtpObj = smtplib.SMTP()smtpObj.connect(mail_host, 25)  # 25 为 SMTP 端口号smtpObj.login(mail_user, mail_pass)smtpObj.sendmail(sender, receivers, message.as_string())print("邮件发送成功")

           

Ruby

# Ruby require 'mail'smtp = { :address => 'smtp.qq.com', :port => 25, :domain => 'qq.com', \         :user_name => '2392863668@qq.com', :password => '****************',\         :enable_starttls_auto => true, :openssl_verify_mode => 'none' }Mail.defaults { delivery_method :smtp, smtp }mail = Mail.new do  from '2392863668@qq.com'  to '2392863668@qq.com'  subject 'Ruby SMTP 邮件测试'  body 'Ruby 邮件发送测试...'endmail.deliver!

                   

转载地址:http://yjjqi.baihongyu.com/

你可能感兴趣的文章
Professional Java User Interfaces
查看>>
The Database Hacker's Handbook: Defending Database Servers
查看>>
IT Administrator's Top 10 Introductory Scripts for Windows
查看>>
Algorithms and Data Structures: The Science of Computing
查看>>
ASP.NET 2.0 Cookbook
查看>>
Java I/O
查看>>
Visual C# 2005 Demystified
查看>>
Unlocking Microsoft C# V 2.0 Programming Secrets
查看>>
Programming Excel with VBA and .NET
查看>>
SQL Server 2005 T-SQL Recipes: A Problem-Solution Approach
查看>>
Core Python Programming
查看>>
Creating Database Web Applications with PHP and ASP
查看>>
ASP.NET 2.0 Demystified
查看>>
Pattern-Oriented Software Architecture, Volume 2, Patterns for Concurrent and Networked Objects
查看>>
Pattern-Oriented Software Architecture, Volume 1: A System of Patterns
查看>>
Database Programming with Visual Basic® .NET and ADO.NET: Tips, Tutorials, and Code
查看>>
Penetration Testing and Network Defense
查看>>
Object-Oriented Programming: From Problem Solving to Java
查看>>
Linux Network Security
查看>>
Essential SourceSafe
查看>>