2016-09-27 84 views
1
def sendEmail(to,apNumber,paperType,zipedFile): 

    sg = sendgrid.SendGridAPIClient(apikey=os.environ.get("API-KEY")) 

    to_email = mail.Email("[email protected]") 
    from_email = mail.Email("[email protected]") 
    subject = 'This is a test email' 
    content = mail.Content('text/plain', 'Example message.') 
    message = mail.Mail(from_email, subject, to_email, content) 
    response = sg.client.mail.send.post(request_body = message.get()) 
    return response 
+0

你確定了'API-KEY'環境變量設置?你使用的操作系統是什麼('API-KEY'在Windows上是一個有效的env變量名,但* nix不允許在名稱中使用'-')。 – mata

+0

我正在使用Ubuntu 16.0。我可以知道如何設置api的環境變量嗎 – vinay

+0

您通常在運行程序之前將其導出到shell中,例如'export API_KEY =「...」' - 閱讀更多[here](https://help.ubuntu.com/community/EnvironmentVariables) – mata

回答

2

安裝環境變量。

要設置環境變量遵循以下3個步驟

echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env 
echo "sendgrid.env" >> .gitignore 
source ./sendgrid.env 
+0

是的,在設置環境變量後,我的問題解決了 謝謝 – vinay