First, you will need to import the System.Net.Mail namespace.
We used over 10 web hosting companies before we found Server Intellect. Our new server with cloud hosting,was set up in less than 24 hours. We were able to confirm our order over the phone. They responded to our inquiries within an hour. Server Intellect’s customer support and assistance are the best we’ve ever experienced.
The System.Net.Mail namespace contains the SmtpClient and MailMessage Classes that we need in order to send the email and specify the CCs.
We used over 10 web hosting companies before we found Server Intellect. Our new server with cloud hosting,was set up in less than 24 hours. We were able to confirm our order over the phone. They responded to our inquiries within an hour. Server Intellect’s customer support and assistance are the best we’ve ever experienced.
The System.Net.Mail namespace contains the SmtpClient and MailMessage Classes that we need in order to send the email and specify the CCs.
using System.Net.Mail;
The front end .aspx page will contain a table to hold all of
our input forms. These forms will accept the variables we will eventually use
in our code behind. We have placed the code in a table to be able to easily
have our form line up and access the information.
<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#cccccc"> <tr> <td width="100" align="right" bgcolor="#eeeeee" class="header1"> To </td> <td bgcolor="#FFFFFF"> <asp:textbox id="txtTo" runat="server" columns="50"></asp:textbox> </td> </tr> <tr> <td width="100" align="right" bgcolor="#eeeeee" class="header1"> From </td> <td bgcolor="#FFFFFF"> <asp:textbox id="txtFrom" runat="server" columns="50"></asp:textbox> </td> </tr> <tr> <td align="right" bgcolor="#eeeeee" class="header1"> CC </td> <td bgcolor="#FFFFFF"> <asp:textbox id="txtCC" runat="server" columns="50"></asp:textbox> </td> </tr> <tr> <td align="right" bgcolor="#eeeeee" class="header1"> BCC </td> <td bgcolor="#FFFFFF"> <asp:textbox id="txtBCC" runat="server" columns="50"></asp:textbox> </td> </tr> <tr> <td align="right" bgcolor="#eeeeee" class="header1"> SMTP Server </td> <td bgcolor="#FFFFFF"> <asp:textbox id="txtSMTPServer" runat="server" columns="50"></asp:textbox> </td> </tr> <tr> <td width="100" align="right" bgcolor="#eeeeee" class="header1"> Subject </td> <td bgcolor="#FFFFFF"> <asp:textbox id="txtSubject" runat="server" columns="50"></asp:textbox> </td> </tr> <tr> <td width="100" align="right" bgcolor="#eeeeee" class="header1"> Body </td> <td bgcolor="#FFFFFF"> <asp:textbox id="txtBody" runat="server" columns="40" textmode="MultiLine"></asp:textbox> </td> </tr> <tr> <td align="right" bgcolor="#eeeeee" class="header1"> Action </td> <td bgcolor="#FFFFFF"> <asp:button id="btnSubmit" runat="server" text="Send Email" onclick="btnSubmit_Click" /> </td> </tr> <tr> <td width="100" align="right" bgcolor="#eeeeee" class="header1"> Status </td> <td bgcolor="#FFFFFF" class="basix"> <asp:literal id="litStatus" runat="server"></asp:literal> </td> </tr> </table>
We use the btnSubmit_Click event to do the work. To access
the event, go to design view and double click on the button. This will take you
into the code behind for our aspx page.
We then call the emailClient.Send to send the message using the variables from our ASP.NET coded page. We use the CC and Bcc methods to add the emails we would like to CC to. We will also be declaring the other variables, such as grabbing the sender and receiver, and accepting a body value for the email.
We then call the emailClient.Send to send the message using the variables from our ASP.NET coded page. We use the CC and Bcc methods to add the emails we would like to CC to. We will also be declaring the other variables, such as grabbing the sender and receiver, and accepting a body value for the email.
protected void btnSubmit_Click(object sender, EventArgs e) { try { MailAddress SendFrom = new MailAddress(txtFrom.Text); MailAddress SendTo = new MailAddress(txtTo.Text); MailAddress SendCC = new MailAddress(txtCC.Text); MailAddress SendBCC = new MailAddress(txtBCC.Text); MailMessage MyMessage = new MailMessage(SendFrom, SendTo); MyMessage.CC.Add(SendCC); MyMessage.Bcc.Add(SendBCC); MyMessage.Subject = txtSubject.Text; MyMessage.Body = txtBody.Text; SmtpClient emailClient = new SmtpClient(txtSMTPServer.Text); emailClient.Send(MyMessage); litStatus.Text = "Message Sent"; } catch (Exception ex) { litStatus.Text=ex.ToString(); } }
No comments:
Post a Comment