As per How do i send email from Azure function app, we are unable to send email directly from our Azure Function, so instead we are using the SendGrid API to send our emails. (SendGrid seems to work well for us, and we get a free account via our Azure subscription)
While most emails go out fine, a handful aren't delivered. The SendGrid activity feed shows a status of Block
for those. The detailed error message is
unable to get mx info: failed to get IPs from PTR record: lookup <nil>: unrecognized address
Since most emails do go out, we don't think it's a problem with our code. We have gone through the SendGrid domain authentication steps, verified our domain, added the DKIM keys to our DNS, and added the SendGrid hosts to our SPF entry. However, a few don't work, and we can't seem to find anything in the SendGrid help on our error.
The code we are using (Python) is largely taken from the SendGrid python example, in case it helps, but this doesn't report any errors when we send.
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
def sendEmail(toaddress, subject, message):
logging.info("Sending email to <%s> - %s", toaddress, subject)
message = Mail(
from_email=settings.emailFrom(),
to_emails=toaddress,
subject=subject,
plain_text_content=message)
try:
sg = SendGridAPIClient(settings.sendgridAPIKey())
response = sg.send(message)
logging.info("Email sent via SendGrid: %d - %s", response.status_code, response.body)
except Exception as e:
logging.error(e.message)