Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a method that uses the mail message class.
Just wondering if it is possible to sync the one of the properties of mail message "mm.body" with the mailto protocol.

Code below:

C#
protected void emailBody()
       {
           MailMessage mm = new MailMessage();

           mm.IsBodyHtml = true;
           mm.Body = PageResult;



       }


ASP.NET
<td>
                <asp:HyperLink ID="HyperLink1" A href="mailto:&Subject=Services Quote&body="  runat="server">Email Quote</asp:HyperLink>

            </td>
Posted

There is not such protocol as "mailto". "mailto:" is just the URI schema, please see:

http://en.wikipedia.org/wiki/URI_scheme[^].

See also:
http://en.wikipedia.org/wiki/URL[^],
http://en.wikipedia.org/wiki/URI[^].

It has nothing to do with the behavior of your Web application and its server part, not related to MainMessage or anything at all. Not that it is not possible to synchronize, the right answer would be: there is nothing to synchronize.

What happens is: your whole code is already executed, as it all happens between HTTP request and HTTP response. If does not matter is you sent some messages to some server, received some messages or anything like that. The pure result of all of this will be delivered to you in HTTP response; and your Web browser has rendered some HTML page, possibly with some URLs, and some of the URLs could be "mailto:". It means nothing for you Web application; it can only be processed on the client side.

Usually, the result of the click causes OS to suggest the user to sent a e-mail message using some default e-mail application. You cannot use any assumption on the behavior caused by the click: the client system may or may not have any e-mail software set up, even the Internet connection may or may not be available at the moment of click.

—SA
 
Share this answer
 
Comments
Andrew Chambers 12-Feb-12 18:02pm    
Hi SA,

I would like to insert the body of my webpage into the email clients body.
Outlook is the email client. Are there any classes I should look at?

Cheers

AC
Sergey Alexandrovich Kryukov 12-Feb-12 19:27pm    
I feel you are somewhat confused about it. It took a separate answer.
Please see my Solution 2.
--SA
[Answering follow-up questions from the comments to Solution 1]

Andrew Chambers wrote:
Hi SA, I would like to insert the body of my webpage into the email clients body. Outlook is the email client. Are there any classes I should look at?
Andrew,

From your questions, I feel you misunderstand e-mail operation or maybe roles of server and client parts in Web application as well as HTTP.

First part of your recent question assume that you want to sent e-mail from your Web application; and you are using the class MailMessage which works on the server side. It has nothing to do with your Outlook e-mail client. When you send e-mail, you don't know the e-mail client of the receiver.

What you do in your Web application is: you generate some Web form in your Web application; it can be a simple static HTML file. It should have the "POST" method of HTTP request. Your server side should get the post data and make e-mail out of it. In other cases, you should use the data available on your server side (such as HTML page you want to send), e-mail address and other headers.

The e-mail message is nothing more but a single block of text data. Even if you have ZIP files "attached" or images, or anything else, you always encode this data in a text format (using base64, etc.). This is all done using multipart MIME messages. All parts are combined into just one single text. If you have any *.EML files — each such file is an exact raw packet send via e-mail.

Now, you need some message transfer agent which is available on you server side. Usually, this is a separate server on a separate (or the same) host with separate (or the same) URI or domain name implementing some mail protocol. Most typically, this is a SMTP server, but it can be something else. You need to check up with your Web hosting provider or setup appropriate server by yourself, if you self-host your HTTP and other servers.

It has nothing to do with you Outlook or any other clients. This is something you need to understand. Please read this:

http://en.wikipedia.org/wiki/Email[^],
http://en.wikipedia.org/wiki/Email_client[^],
http://en.wikipedia.org/wiki/Mail_transfer_agent[^],
http://en.wikipedia.org/wiki/SMTP[^].

Better now?

Now, let's see how multipart messages could be created. Basically, creation of such messages in nothing more but composing some text following e-mail standard, specified in a number of IETF RFC documents.

Please see:
http://en.wikipedia.org/wiki/Request_for_Comments[^].

MIME RFCs are listed here:
http://en.wikipedia.org/wiki/MIME[^].

See also:
http://www.ietf.org/rfc/rfc1867.txt[^].

See also: http://www.iana.org/assignments/message-headers/perm-headers.html[^].

Please find a code sample using .NET System.Net.Mail:
http://www.systemnetmail.com/faq/3.1.3.aspx[^].

Warning! If you ever need to form a mail based on user's submission: be extra careful. It's way too easy to exploit your HTTP host to turn it into a zombie sending spam or something else. Please see my recent post:
unable to send mail , it showing the error in below code .[^].

—SA
 
Share this answer
 
v3
Comments
Andrew Chambers 13-Feb-12 2:35am    
I guess what your saying SA, is that it is not possible to press a button on an asp.net page to open Outlook and have that web pages' content in the body of the email.

Is this correct? It is a requirement for the project I am working on that the asp.net page do this. If I am unable to do this with asp.net I will look at other options.

Thanks

AC

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900