Forum

Author Topic: Python send email  (Read 3092 times)

tillwadell

  • Newbie
  • *
  • Posts: 4
    • View Profile
Python send email
« on: October 20, 2017, 03:00:50 PM »
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

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14839
    • View Profile
Re: Python send email
« Reply #1 on: October 23, 2017, 01:21:37 PM »
Hello tillwadell,

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

tillwadell

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Python send email
« Reply #2 on: October 26, 2017, 09:56:33 AM »
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

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14839
    • View Profile
Re: Python send email
« Reply #3 on: October 26, 2017, 10:48:08 AM »
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