相关疑难解决方法(0)

如何从 Azure 函数应用发送电子邮件?

我运行了 Azure 函数应用程序(python 语言),业务需求需要从函数应用程序发送电子邮件。

为此,我写了一个 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
Run Code Online (Sandbox Code Playgroud)

以上代码块在本地机器上工作正常。如果我将相同的代码移动到 Azure Function App,它就不起作用。

如何使其在 Azure 函数应用上运行?

如何在 Azure Function App 中从Gmail发送电子邮件?

email azure smtplib python-3.x azure-functions

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

azure ×1

azure-functions ×1

email ×1

python-3.x ×1

smtplib ×1