我运行了一个使用Python语言的Azure函数App,因为业务需求需要从函数应用程序发送电子邮件。
为此,我编写了一个Python函数。
from email.message import EmailMessage
import smtplib
def send_mail():
# message to be sent
msg = EmailMessage()
msg.set_content('Test content')
msg['Subject'] = 'Test'
msg['From'] = "test@hotmail.com"
msg['To'] = ["test@hotmail.com"]
# creates SMTP session
s = smtplib.SMTP('smtp-mail.outlook.com', 587)
s.ehlo()
# start TLS for security
s.starttls()
# Authentication
s.login("test@hotmail.com", "password-to-login")
# sending the mail
s.send_message(msg)
# terminating the session
s.quit()
return
上述代码在本地机器上运行正常。如果我将相同的代码移动到 Azure Function 应用程序中,它就无法工作。
我该如何使其在 Azure Function 应用程序中正常工作?
我该如何在 Azure Function 应用程序中使用 Gmail 发送电子邮件?