Hi all! Does anyone have an idea, why this code actually works and sends emails, but Fails on: send_email("admin@checkio.org","Alex") test on 'Check'? This assert actually could be passed, if I copy it directly into the 'asserts' block below my main code.
import sendgrid
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail, Content
API_KEY = "somekey"
SUBJECT = "Welcome"
BODY = "Hi {name}"
sg = sendgrid.SendGridAPIClient(API_KEY)
def send_email(email, name):
global API_KEY
global SUBJECT
global BODY
body=BODY.replace("{name}",name)
message = Mail(
from_email = "hustlingnotagame@gmail.com",
to_emails = email,
subject = SUBJECT,
html_content = BODY)
message.content = Content("text/plain", body)
print(message)
try:
sg = sendgrid.SendGridAPIClient(API_KEY)
response = sg.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print(e.message)
Created at: 2019/10/06 11:08; Updated at: 2019/10/06 14:32
The question is resolved.