Sending mail in outlook through a mail template

RTT

Active member
Joined
Mar 16, 2005
Messages
26
Programming Experience
Beginner
Hi,

In my code i want to open a mail template like when you click a mailto-link, so the person views the mail, but the mail uses a certain template. Certain things should already be filled in when the person gets the mail. Like send to, subject and some parts of the template. Other things have to be filled in by the person himself. after the mail is ready he just has to hit send to send the mail.

So the mail should open in outlook using a template where parts are filled in in advance. Does anybody has an idea on how to start on this?

thxs in advance....

greetz
 
You can just use Process.Start() with a mailto: URL as the file name. This will open a new mail message in the user's default e-mail client. If you are not aware, you can fill various e-mail fields like so:

Process.Start("mailto:person@domain.com?cc=email1@domain.com;email2@domain.com&bcc=email3@domain.com&subject=subject text&body=body text")

One important thing to be aware of, as I found out by doing the same thing, is that the filename argument to Process.Start() cannot be more than about 2020 characters. I'm not sure of the exact figure.
The good thing about using this method over SmtpMail is that the user ends up with a copy of the message in their Sent Items folder and your application doesn't need to know anything about e-mail except how to build a mailto: URL.
 
Last edited:
Just edited my previous post.

Process.Start("mailto:person@domain.com?cc=email1@domain.com;email2@domain.com&bcc=email3@domain.com&subject=subject text&body=body text")

Start(filename) is a Shared function of the System.Diagnostics.Process class.
 
Last edited:
moet je hier niet ergens meegeven welk programma ofzo je gebruikt. want ik krijg
deze error:

The system cannot find the file specified

[font=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified

Source Error:

Line 33: ''sBodyText = "body text here" & vbCr & "testing testing"Line 34: ''Call My_Mailto("si_the_geek@example.com", "subject here", sBodyText)Line 35: System.Diagnostics.Process.Start("mailto:person@domain.com?cc=email1@domain.com;emai l2@domain.com&bcc=email3@domain.com&subject=subject text&body=body text")Line 36: Line 37:
Source File: c:\inetpub\wwwroot\WebApplication10\WebForm1.aspx.vb Line: 35

Stack Trace:

[Win32Exception (0x80004005): The system cannot find the file specified] System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) System.Diagnostics.Process.Start() System.Diagnostics.Process.Start(ProcessStartInfo startInfo) System.Diagnostics.Process.Start(String fileName) WebApplication10.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\WebApplication10\WebForm1.aspx.vb:35 System.Web.UI.Control.OnLoad(EventArgs e) System.Web.UI.Control.LoadRecursive() System.Web.UI.Page.ProcessRequestMain()[/font]
 
I've never had any trouble with this method, but then I've only ever used it from a WinForms app and only to populate the BCC field. I'm guessing that you'll need to replace spaces with "%20", or whatever the code is for spaces in URLs, and possibly replace other special characters as well.
 
I found this code: http://www.c-sharpcorner.com/Internet/SendingEmailsThroughOutlookCB.asp and this work partly...

with this code i can save the mail in the draft folder. But i can't get it to display to the user. mailitem.display does not seem to work.

so now i'm searching for a way to open of focus on the mail in outlook once it's created....

does anybody has an idea how i can do this?
 
If you check the Help for Microsoft Outlook in the Microsoft Outlook Visual Basic Reference section, you find the MailItem object under Objects | M. The help topic has an example that uses the MailItem.Display method. Without having tested it, I'm guessing that this is what you're after.

Just one point to note, which you may well have already considered: the method you are using will only work if the user has Outlook installed.
 
jmcilhinney said:
If you check the Help for Microsoft Outlook in the Microsoft Outlook Visual Basic Reference section, you find the MailItem object under Objects | M. The help topic has an example that uses the MailItem.Display method. Without having tested it, I'm guessing that this is what you're after.

Just one point to note, which you may well have already considered: the method you are using will only work if the user has Outlook installed.

maybe a stupid question but where do i find: Microsoft Outlook Visual Basic Reference section?

every user has outlook installed and running when they visit the webpage... that's what i'm sure of...
 
jmcilhinney said:
Just edited my previous post.

Process.Start("mailto:person@domain.com?cc=email1@domain.com;email2@domain.com&bcc=email3@domain.com&subject=subject text&body=body text")

Start(filename) is a Shared function of the System.Diagnostics.Process class.

found a way to make it work.. but oulook allows voting. is there a way to give the voting options with the mailtostring?
 
I must admit, I've installed Office many times and there does seem to be differences between what's available in help on various occasions. I have no explanation for it. I have set Office (2003) to download the most up-to-date table of contents from Microsoft, so you might try that.

As for voting options, Outlook help has this to say:

MailItem.VotingOptions property
Returns or sets a String specifying a delimited string containing the voting options for the mail message. Read/write.

What that delimited string might contain, I'm not sure. When I create a new message in Outlook and open the Options dialogue, the voting options drop-down list includes Approve;Reject, Yes;No and Yes;No;Maybe. I would guess that you can set the VotingOptions property to any of these or an empty string.
 
Last edited:
Back
Top