def yagmail(self): #如果有开启邮件服务 ''' Mail_username = self.Mail_user.text() Mail_passwd = self.Mail_passwd.text() Server_host = self.Server_host.text() Server_port = self.Server_port.text() #Mail_list = [Mail_username, Mail_passwd, Server_host, Server_port] ''' # 链接邮箱服务器 yag = SMTP(user=self.username, password=self.pwd, host=self.host, port=self.port) # 发送邮件 yag.send( to=self. username, # 如果多个收件人的话,写成list就行了,如果只是一个账号,就直接写字符串就行to='*****@*****.**' #cc='*****@*****.**', # 抄送 subject='for_test', # 邮件标题 contents=self.content, # 邮件正文 #attachments=[r'd://log.txt', r'd://baidu_img.jpg'] # 附件如果只有一个的话,用字符串就行,attachments=r'd://baidu_img.jpg' ) #可简写成: #yag.send('*****@*****.**', '发送附件', contents, ["d://log.txt", "d://baidu_img.jpg"]) # 关闭 yag.close()
def send_mails(emitter, password, contacts, content): yag = SMTP(emitter, password) phr = content['Phrase'] des = content['Definition'] exa = content['Example'] body = 'Phrase: {}\nDefinition: {}\nExample: {}'.format(phr, des, exa) for name, reciever in zip(contacts['Names'], contacts['Mails']): yag.send( to=reciever, subject="Hola {}, esta es la frase de hoy".format(name), contents=body, ) yag.close()
def yagmail_test(self): # 链接邮箱服务器 yag = SMTP(user=self.username, password=self.pwd, host=self.host, port=self.port) # 发送邮件 yag.send(to=self.username, subject='for_test', contents='test for script') #yag.send('*****@*****.**', '发送附件', contents, ["d://log.txt", "d://baidu_img.jpg"]) # 关闭 yag.close()