Forum

Python send email

Started by tillwadell, October 20, 2017, 03:00:50 PM

Previous topic - Next topic

tillwadell

We have this python below as the last step in our batch processes to let us know when it is finisged. I am now trying to implement more information from PhotoScan in that email. I would like that the email could include the name of the actual project. I cant really figure out how to implement this.


import smtplib
import PhotoScan

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


import socket
namn = socket.gethostname()


fromaddr = "*****@***.com"
toaddr = "****@***.***"
doc = PhotoScan.app.document
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Dator: " + socket.gethostname() + " - Photoscan Align Finished"

body = "Hej, " + socket.gethostname() + "is now finished with Align."
msg.attach(MIMEText(body, 'plain'))

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "**********")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()

Alexey Pasumansky

Hello tillwadell,

You can access the project's name using the path to the project: doc.path.
Best regards,
Alexey Pasumansky,
Agisoft LLC

tillwadell

Could you elaborate?

If I would like to add it to this row, red text

msg['Subject'] = "Dator: " + socket.gethostname() + " - Photoscan Align Finished" + doc.host?????

Alexey Pasumansky

Hello tillwadell,

The name of the project file can be taken from the path to the project:

doc_name = doc.path.rsplit("/",1)[1]
Best regards,
Alexey Pasumansky,
Agisoft LLC