首页 \ 问答 \ 如何使用Python发送Gmail作为提供者的电子邮件?(How to send an email with Gmail as provider using Python?)

如何使用Python发送Gmail作为提供者的电子邮件?(How to send an email with Gmail as provider using Python?)

我正在尝试使用python发送电子邮件(Gmail),但是我收到以下错误。

Traceback (most recent call last):  
File "emailSend.py", line 14, in <module>  
server.login(username,password)  
File "/usr/lib/python2.5/smtplib.py", line 554, in login  
raise SMTPException("SMTP AUTH extension not supported by server.")  
smtplib.SMTPException: SMTP AUTH extension not supported by server.

Python脚本如下。

import smtplib
fromaddr = 'user_me@gmail.com'
toaddrs  = 'user_you@gmail.com'
msg = 'Why,Oh why!'
username = 'user_me@gmail.com'
password = 'pwd'
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

I am trying to send email (Gmail) using python, but I am getting following error.

Traceback (most recent call last):  
File "emailSend.py", line 14, in <module>  
server.login(username,password)  
File "/usr/lib/python2.5/smtplib.py", line 554, in login  
raise SMTPException("SMTP AUTH extension not supported by server.")  
smtplib.SMTPException: SMTP AUTH extension not supported by server.

The Python script is the following.

import smtplib
fromaddr = 'user_me@gmail.com'
toaddrs  = 'user_you@gmail.com'
msg = 'Why,Oh why!'
username = 'user_me@gmail.com'
password = 'pwd'
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

原文:https://stackoverflow.com/questions/10147455
更新时间:2023-02-01 14:02

最满意答案

据我所知,在互联网的早期阶段,Netscape创建了Refresh(与Set-Cookie以及可能的其他专有伪头文件),自那以来基本上(但不完全)标准化。 因为每个浏览器都支持它,所以刷新是非常安全的 - 通常是。

我想它从来没有成为官方标准的一部分,因为他们已经有了与状态代码的规定。


As far as I know, Refresh (along with Set-Cookie and possibly some other proprietary pseudo-headers) were created by Netscape in the very early days of the internet and have been basically (but not quite) standard since then. Because just about every browser supports it, Refresh is pretty safe to use -- and commonly is.

I guess it never became part of the official standards because they already had provisions for that with the status codes.

相关问答

更多
  • 我不明白为什么不。 OPTIONS请求方法用于请求有关可用于请求的URI的通信选项的信息。 某些客户端使用OPTIONS来确定通信要求和服务器的功能,而无需在请求资源上检索或执行操作。 I don't see why not. The OPTIONS request method is used to request information about the communication options available for the requested URI. Some clients use OP ...
  • 您需要使用NSMutableURLRequest NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease]; [request setValue:VALUE forHTTPHeaderField:@"Field You Want To Set"]; 或添加标题: [request addValue:VALUE forH ...
  • 配置对象中有一个头参数,每个调用头都传递给$http : $http({method: 'GET', url: 'www.google.com/someapi', headers: { 'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='} }); 或使用快捷方式: $http.get('www.google.com/someapi', { headers: {'Authorization': 'Basic QWxhZGRpbjpvcG ...
  • 单独引荐检查不会对您有所帮助,并且可能会影响用户,因此最好不要依赖它。 ASP.NET可以帮助你通过视图状态缓解CSRF:每个回发必须包含视图状态,否则该框架将引发异常,并且由于攻击者无法读取它(读取视图状态,他必须获取页面,并跨站点AJAX请求不被允许)攻击将失败。 然而,正如V4Vendetta 指出仅靠viewstate 是不够的 :如果页面不包含每个用户独特内容的控件,viewstate对于不同的用户将是相同的,所以攻击者可以简单地提交他的viewstate。 为了防止出现这种情况,您可以将此代码放 ...
  • 据我所知,在互联网的早期阶段,Netscape创建了Refresh(与Set-Cookie以及可能的其他专有伪头文件),自那以来基本上(但不完全)标准化。 因为每个浏览器都支持它,所以刷新是非常安全的 - 通常是。 我想它从来没有成为官方标准的一部分,因为他们已经有了与状态代码的规定。 As far as I know, Refresh (along with Set-Cookie and possibly some other proprietary pseudo-headers) were create ...
  • 我需要每120秒刷新一次页面 嗯,我有点怀疑,因为这里没有页面。 页面(以及后面使用的术语“刷新代码” )意味着涉及HTML( “HTML页面” ),但不涉及HTML。 根据您设置的Content-Type,XML - 而不是HTML - 涉及: header("Content-Type: application/rss+xml; charset=UTF-8"); echo ''; 由于涉及XML而不涉及HTML,因此不涉及HT ...
  • 所以你想在登录后在进一步的请求中添加你的令牌。 你可以尝试角度拦截器。 这里有几个答案相关如何通过拦截器添加toke。 拦截器例1 拦截器示例2 示例代码: app.factory('httpRequestInterceptor', function () { return { request: function (config) { config.headers['Authorization'] = $cookieStore.get('Auth-Key'); ...
  • isDefined()的用法非常有限,所以不能使用关联数组符号。 无论如何,在几乎所有情况下,最好使用StructKeyExists()。 所以,要解决你的问题: 使用: isDefined() is very limited in it's usage, so you can't use associative array notation with it. In almost ...
  • HTTP / 2网站通常使用TLS,因为浏览器仅通过TLS支持HTTP / 2。 您尝试使用的方法是HTTP / 1.1升级到HTTP / 2,很少有站点(如果有的话)支持。 您的代码片段代表请求 ,而不是响应。 如果升级成功,HTTP / 2服务器将以HTTP / 1.1格式发回101响应, 并以HTTP / 2格式发送对GET请求的响应。 这在RFC 7540第3.2节中规定。 为了实现您想要的,即知道网站是否支持HTTP / 2,您必须尝试使用HTTP / 2 + TLS进行连接。 如果连接成功,则表 ...
  • 来自RFC2616第4.2节: 当且仅当该头字段的整个字段值被定义为以逗号分隔的列表[即,#(值)]时,具有相同字段名的多个消息头字段可以存在于消息中。 必须可以将多个头字段组合成一个“字段名:字段 - 值”对,而不改变消息的语义,方法是将每个后续字段值附加到第一个字段值,每个字段值用逗号分隔。 因此,接收具有相同字段名称的头字段的顺序对于组合字段值的解释是重要的,因此代理不得在转发消息时改变这些字段值的顺序。 编辑: 根据14.10节,Connection是一个字段名称,因此具有多个Connection头 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)