0

I would like to send emails from Azure Databricks. I try to do this: https://docs.databricks.com/_static/notebooks/kb/notebooks/send-email-aws.html

But when I execute this: send_email(from_addr, to_addrs, subject, html, attachments=attachments)...

...this error appears: NoCredentialsError: Unable to locate credentials

Thanks in advance!

  • Sending an email from with Databricks is quite easy using Amazon SES. In order to do this, you'll have to make sure that you have access and proper permissioning with the AWS SES service. – Pratik Lad Dec 13 '22 at 10:58
  • As the first line states, please set up the necessary access controls in SES and maybe you need to configure the boto file ? Not sure - but see if the link is applicable - https://docs.aws.amazon.com/ses/latest/dg/control-user-access.html - https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration – rainingdistros Dec 14 '22 at 06:24

1 Answers1

0

I agree with the discussion in comments.

If you want, you can try sending mail from databricks using logic apps as an alternative.

First store your attachment as dataframe and save as a file in blob storage.

In input data of logic app post request pass the file name as well.

Databricks code:

import requests as req
import json

input_data = {"Fromaddress":"mail","Notebookname":"Nb1","Toaddress":"<To mail>","filepath":"attachment.csv"}

url = '<your logic app POST URL>'

resp = req.post(url, data=input_data)
print(resp.text)

enter image description here

In logic app use When a HTTP request is received and give Body like below as per the input data in databricks.

{
"properties": {
"$content": {
"type": "string"
},
"$content-type": {
"type": "string"
},
"$formdata": {
"items": {
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"key",
"value"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
}

enter image description here

Then I have used a compose to store the attachment file name.

triggerBody()?['$formdata'][3]['value']

Then use Get blob content using path (V2). create connection and give the container name and for file name give the output of compose like below.

enter image description here

Then use send mail action and give triggerBody()?['$formdata'][1]['value'] for To address. add attachment in new parameter and for attachments content give the File Content from Blob and for attachment Name, you can give compose output.

enter image description here

Execute the Code in databricks notebook and flow will succeed.

enter image description here

RESULT:

enter image description here

Rakesh Govindula
  • 5,257
  • 1
  • 2
  • 11