Winform in Dynamo

I’ve got a lovely winform…

And I want to add an email link. I’ve tried about 600 different ways and all I can get it to open is a blank page with my emails.

This one is with import subprocess.

	def open_email(self):		
		subprocess.Popen(["start", "outlook", "mailto:" + email_address], shell=True)

# Call the form
if runme:
	form = CreateWindow()
	Application.Run(form)
	form.open_email()

I tried:

System.Diagnostics.Process.Start(“outlook.exe”, “mailto:” + email_address)

and

os.startfile(“mailto:” + email_address)

This is what I get:

AND a blank webpage opens too!

@Alien Try this:

import webbrowser

class CreateWindow:
    def open_email(self, email_address, subject, body):
        mailto_link = f"mailto:{email_address}?subject={subject}&body={body}"
        webbrowser.open(mailto_link)

# Example usage:
runme = True  # Set this to your condition
if runme:
    form = CreateWindow()
    # Provide the email address, subject, and body for the email
    form.open_email("recipient@example.com", "Your Subject", "Your email content goes here.")

2 Likes

It probably works too if you leave out the application:

System.Diagnostics.Process.Start(“mailto:” + email_address)

It depends on Windows which application will start.

1 Like

I’d already tried webbrowser and had no luck.
I’ve just tried what you put but as usual I get a syntax error with f strings. :frowning:

It just says, “invalid syntax” which is hopelessly unhelpful.

That just opens a blank webpage. No email.

Have a look at gavins crumple package, there is a node there using ironpython 2 for emailing that you can investigate for your needs. :slight_smile:

1 Like

Some progress :smiley:

You have probably a browser connected to the mailto type. You can change that in Windows Settings, Default Apps:

Dialog is in Dutch.

But you can’t force this for users of your graph, so probably you should look at a more robust solution that will work on every computer.

1 Like

image

This is working :slight_smile: based on the Crumple code. :slight_smile:

All I have to do now is work out how to incorporate it into the winform :smiley:

Whoo. That took way longer than anticipated but was fun. :smiley:

Thanks all!

3 Likes