Pergunta

I just want to be able to pre-populate a MailMessage object with all the properties of the email (from, to, subject, body, and an attachment file) and present it to the web client to decide whether to send it as is, or edit the email further before hitting send.

Is there a way to do this in C# using asp.net (.net 2) via Visual Studio 2005?

Thank you

Foi útil?

Solução

Create a page (or a dialog box, I prefer using jQuery UI but I'm going to do this example as a page cuz I'm lazy)

To: <asp:TextBox runat="server id="To_TB /><br />
Subject: <asp:TextBox runat="server" id="Subject_TB" /><br />
Body:<br />
<asp:TextBox runat="server" id="Body_TB" TextMode="Multiline" /
<br />
<asp:Button runat="server" id="Submit_BTN" Text="Send Email" OnClick="Submit_BTN_Click" />

Codebehind...

protected void Submit_BTN_Click(object sender, EventArgs e)
{
    MailMessage msg=new MailMessage("myserver@mysite.com", To_TB.Text, Subject_TB.Text, Body_TB.Text);
    SmtpClient client=new SmtpClient("myemailserver@mydomain.com");
    client.Send(msg);
}

It can obviously me much fancier, HTML emails and MailAddress instead of strings and all that jazz. But this should get you started. You'll have full control over it, unlike depending on the user having an email client.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top