Forum

Author Topic: ---=== Email when a Metashape project is finished ===---  (Read 1871 times)

c-r-o-n-o-s

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
---=== Email when a Metashape project is finished ===---
« on: December 30, 2021, 11:58:09 AM »
Hello,

I am looking for a "simple" solution to send an email when a Metashape project is finished.
(To be used in a batch process.)

There is already an approach here:
https://www.agisoft.com/forum/index.php?topic=7889.0

I need a "simpler approach", without registering SMTP servers etc.
At my work we use Outlook and have no direct access to the servers.
A simple "Mail:TO" or similar must be enough.
Then a mail should be sent by the user who is currently logged in.

Does anyone already have something like this in use and could make it available?

Thanks in advance!

c-r-o-n-o-s

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: ---=== Email when a Metashape project is finished ===---
« Reply #1 on: December 30, 2021, 12:58:29 PM »
OK, this one works with a standard text.

import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'XXX@XXX.XX'
mail.Subject = 'SAMPLETEXT'
mail.Body = 'SAMPLETEXT'
mail.Send()


With Alexey Pasumansky's suggestion to use the project name, it doesn't work.
(However, the suggestion is from 2017. Maybe it doesn't work with the 1.7.5 version?)

SAMPLETEXT = doc.path.rsplit("/",1)[1]
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'XXX@XXX.XX'
mail.Subject = SAMPLETEXT
mail.Body = SAMPLETEXT
mail.Send()


Unfortunately, my scipting skills are very limited...  :o
However, a standard text is more than enough for now.
« Last Edit: December 30, 2021, 01:01:04 PM by c-r-o-n-o-s »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14965
    • View Profile
Re: ---=== Email when a Metashape project is finished ===---
« Reply #2 on: December 30, 2021, 02:08:38 PM »
Hello c-r-o-n-o-s,

The following line should return the project filename, providing that the project has been saved and is opened in the active Metashape window:
Code: [Select]
SAMPLETEXT = Metashape.app.document.path.rsplit("/",1)[1]
Best regards,
Alexey Pasumansky,
Agisoft LLC

c-r-o-n-o-s

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: ---=== Email when a Metashape project is finished ===---
« Reply #3 on: December 30, 2021, 02:20:11 PM »
Excellent, it works!
Until now, I had always tested it on a non-safe project.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14965
    • View Profile
Re: ---=== Email when a Metashape project is finished ===---
« Reply #4 on: December 30, 2021, 03:34:23 PM »
Hello c-r-o-n-o-s,

You can add some check in order to deal with "untitled" projects as well:
Code: [Select]
if not Metashape.app.document.path:
    SAMPLETEXT = "untitled project"
else:
    SAMPLETEXT = Metashape.app.document.path.rsplit("/",1)[1]
Best regards,
Alexey Pasumansky,
Agisoft LLC