开发者

Send Email like @mailto but from code behind ASP.Net

Scenario: We are using a createwizard control to create users for our website. When the user has an email we simply send the user the email with their username and password saying their account has been created. Using MailMessage and SMTPClient.

Problem: When the user doesn't have an email (ex. temp employee, student) I need to be able to generate the email but have it open via the creator's mail client so that they can enter in a开发者_StackOverflown email themselves/see the username and password. Similar to @mailto functionality.

Question: Is there a way to do this from the code behind? I have tried searching but everywhere is telling me to use MailMessage and SMTPClient which I don't need.

Thanks in advance.


You can create a mailto-link and click it with JavaScript.

See here: How do I programmatically click a link with javascript?

Or you can create a form with textboxes "To, Subject and Body", and a button send, where you wait 'till the user filled it out (the to field), then you send the mail with smtpclient.

On a sidenote: why not just prompt for an email address and then send it there ?


Well.. you can do a response.write or use a substitution control somewhere that links to a function that generates the propertly a href=mailto:.......etc. html

if you want it done automatically, you can do a javascript target redirect


I think I finally understand what you're after. This code should work:

string sMailTo = "putmailhere@domain.com";
string subject = "New member data";
string body = "New member has been added.\nName: John Doe\nPassword: pass";
Process.Start(string.Format("mailto:{0}?subject={1}&body={2}", sMailTo, Uri.EscapeUriString(subject), Uri.EscapeUriString(body)));

Note that you can use only plain text, from what I've seen you can't force HTML format.

Edit: Since it's ASP.NET application this approach is actually useless, as the mail client will open on the server machine not the visitor machine.

Leaving this for those who use WinForms or any non web environment.

For ASP.NET only way is client side script invoking <a href="mailto:..."> anchor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜