quarenjo
quarenjo

Reputation: 47

How can a predefined email be opened with the default email program in Windows?

I'm searching for a possibility to generate a predefined mail when the user clicks on a button in a tcl/Tk program. Up to now I'm using the mailto-protocol, but as the predefined message may have a long body, the message may be cut at some point. Thus, this is no real solution.

All alternatives I found up to now have some drawbacks. So, is there a possibility which meets following requests?

It would be no solution to just send a Mail in the background, as it should be really transparent what happens and which information is send... (I know there are already many questions about similar topics, but I haven't found a solution which worked for me.)

Upvotes: 0

Views: 177

Answers (1)

kostix
kostix

Reputation: 55563

It should be possible to automate sending mails on Windows via tcom by using the CDO.Message COM object.

That's a Windows-only solution.

A cross-platform solution which should work everywhere is using the package mime to construct the message and smtp to send it. Both are part of "the standard Tcl library", tcllib, available on any sensible system which has Tcl packaged.

As to

It would be no solution to just send a Mail in the background, as it should be really transparent what happens and which information is send...

I failed to parse it. Could you may be try to reformulate?


Update:

Well, OK, after re-reading the title I think I completely fail to understand the essense of the question.

If everything what's needed is opening a e-mail message — as in "a file with MIME-formatted text representing an e-mail message", — I think that's hardly possible because a "default program to handle e-mails" is specified for URIs having the mailto scheme.

If what's needed is to spawn a default mail client on Windows asking it to open a window to let the use compose an e-mail message destined to the predefined address, the you can use

exec [list rundll32.exe uri.dll,FileProtocolHandler "malto:$addr"]

where the addr variable contains the recipient's e-mail address.

The mailto: URIs allow specifying the message body (and may be that's what you're currently using) but they (rightfully) do not allow specifying a file name to interpret as a message, so there appears to be no way to open a mail client with a pre-made message.


Update #2:

OK, so may be I finally got what did you mean by saying "should be really transparent...". You mean the user has to see with their own eyes what will be sent, right? But what's wrong with just emulating an e-mail client by presenting the user with a dialog window showing which will be sent? This is used by every software product I have seen which had a similar feature. Various Microsoft and Mozilla products come to mind as the most visible examples. They just offer you a dialog box to browse what will be sent.

Note that even if the user saw "what will be sent" in a true mail client and hit "Send" with their own hand, nothing prevents any host among those which will be handling this message (usually two at least) from modifying it unless it was a cryptographically signed message (in S/MIME format).

Are you sure you want to go that far?

Upvotes: 2

Related Questions