나는 개인 SMTP 서버에 이메일을 보내려고하고 있고 sendgrid -받는 사람 SMTP 서버를 지정하는 방법은 무엇입니까?
s = smtplib.SMTP(server, port)
s.sendmail(me, you, msg.as_string())
이
Sendgrid (푸른 블록 SMTP 등)에 동일한 변환하려고 다음과 같이 파이썬
smtplib
를 사용하여 그렇게 할 수 있지만 할 수있는 옵션이 없습니다 개인 SMTP 서버를 지정하십시오.
import sendgrid
import os
from sendgrid.helpers.mail import *
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
from_email = Email("[email protected]")
to_email = Email("[email protected]")
subject = "Sending with SendGrid is Fun"
content = Content("text/plain", "and easy to do anywhere, even with Python")
mail = Mail(from_email, subject, to_email, content)
response = sg.client.mail.send.post(request_body=mail.get())
print(response.status_code)
print(response.body)
print(response.headers)
모든 도움을 주시면 감사하겠습니다.
감사
아주 정상입니다
답변 해 주셔서 감사합니다. 근본적인 문제는 SMTP 보내기가 Microsoft Azure에서 차단되고 (또한 AWS가 의심 스럽습니다) sendgrid와 같은 릴레이 서비스를 사용하는 것이 좋습니다. 그러나 smtp를 사용하기 위해 sendgrid를 수정해야한다면 Azure 블로킹 문제를 어느 쪽이든 겪을 것으로 생각됩니다. – dopplesoldner
릴레이 역할을하는 SMTP 서버에 가까운 API 끝점을 만들어야합니다. 당신은 하늘에서 HTTPS로 나가 API 끝점을 가리킨다. 이 질문을 닫을 수 있습니다. 귀하의 질문에 답변 할 수있는 방법은 없습니다.) –