我试过在函数中调用 stmplib.login 。我环顾四周,但找不到太多适合课堂的方法。sendmail 在三个地方被调用,因此需要在一个地方初始化 smtplib.smtp 并在不同的函数中调用它。
老实说,我喜欢此链接的作者 ( http://learnpythonthehardway.org/book/ex43.html ) 解释如何进行课程的简单性。我得到它。之前,我继续前进,我在网上遇到了一个错误
self.smtpaccess.login(self.MAILUSER, self.MAILPASSWORD)
它说
AttributeError: 'str' object has no attribute 'login'
我在面向对象方面的想法是否正确
class outLook(object):
def __init__(self,ms,mpr,mu,mps):
self.smtpaccess = ""
self.MAILSERVER = ms
self.MAILPORT = mpr
self.MAILUSER = mu
self.MAILPASSWORD = mps
def authenticate(self):
try:
self.smtpaccess = smtplib.SMTP(self.MAILSERVER , self.MAILPORT)
self.smtpaccess.starttls()
self.smtpaccess.ehlo()
except smtplib.socket.gaierror:
print 'smtplib.socket.gaierror'
def outlookLogin(self):
try:
self.smtpaccess.login(self.MAILUSER, self.MAILPASSWORD)
except smtplib.SMTPAuthenticationError:
print 'SMTPAuthenticationError'
def sendMailToProducer(self):
pass
def sendMailToArtist(self,name):
pass
outLookResult = outLook('smtp.office365.com',nnn,'xxxxxxxxsupport@xxxxxxxxxx.in','xxxxnnnnn')
outLookResult.outlookLogin()