An Azure service that provides an event-driven serverless compute platform.
Thanks for posting your question in the Microsoft Q&A forum.
To complete this action, follow these steps:
- Install the necessary packages such as
pandas,openpyxl,requests, andsmtplib. - Use the
requestslibrary to authenticate with SharePoint and download the Excel file. Then, usepandasto read the Excel data into a DataFrame. - You can use the
smtpliblibrary to send emails in Python. - Make sure to include the required Python libraries (
openpyxl,requests, ...) in your function app's requirements.txt file.
import requests
import smtplib
from email.mime.text import MIMEText
from openpyxl import load_workbook
site_url = "https://test.sharepoint.com/sites/mysite"
file_url = f"{site_url}/_api/web/GetFileByServerRelativePath(decodedurl='/sites/mysite/Shared Documents/myexcelfile.xlsx')/\$value"
response = requests.get(file_url, auth=("******@test.com", "password"))
with open("temp.xlsx", "wb") as f:
f.write(response.content)
workbook = load_workbook("temp.xlsx")
worksheet = workbook.active
data = worksheet.values
smtp_server = "smtp_server"
smtp_port = 25
smtp_username = "******@test.com"
smtp_password = "password"
sender = "******@test.com"
receiver = "******@test.com"
subject = "Subject"
body = "Email body"
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = receiver
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(smtp_username, smtp_password)
server.send_message(msg)
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful