本文介绍了Python 在代理服务器后面发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 hotmail smtp 使用 python 脚本发送电子邮件,但我已连接到代理服务器.

I want to send an email using python script via hotmail smtp but I'm connected to a proxy server.

有我的代码,当它直接连接到互联网时它可以工作,但是当它连接到代理服务器时他不起作用.

There is my code , it works when it's connected directely to internet but wen it's connected to a proxy server he doesn't work.

import smtplib

smtpserver = 'smtp.live.com'
AUTHREQUIRED = 1
smtpuser = '[email protected]'
smtppass = 'mypassword'

RECIPIENTS = '[email protected]'
SENDER = '[email protected]'
mssg = "test message"
s = mssg

server = smtplib.SMTP(smtpserver,587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(smtpuser,smtppass)
server.set_debuglevel(1)
server.sendmail(SENDER, [RECIPIENTS], s)
server.quit()

推荐答案

您可以使用名为 SocksiPyPySocks,目前维护的分支:

You can accomplish this with a module called SocksiPy or PySocks, the currently maintained fork:

import smtplib
import socks

#socks.setdefaultproxy(TYPE, ADDR, PORT)
socks.setdefaultproxy(socks.SOCKS5, 'proxy.proxy.com', 8080)
socks.wrapmodule(smtplib)

smtpserver = 'smtp.live.com'
AUTHREQUIRED = 1
smtpuser = '[email protected]'
smtppass = 'mypassword'

RECIPIENTS = '[email protected]'
SENDER = '[email protected]'
mssg = "test message"
s = mssg

server = smtplib.SMTP(smtpserver,587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(smtpuser,smtppass)
server.set_debuglevel(1)
server.sendmail(SENDER, [RECIPIENTS], s)
server.quit()

这篇关于Python 在代理服务器后面发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 12:53