-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContactUs.aspx.cs
44 lines (41 loc) · 1.9 KB
/
ContactUs.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Net.Mail;
using System.Configuration;
public partial class ContactUs : System.Web.UI.Page
{
public void btnSend_Click(object sender, EventArgs e)
{
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(new System.Net.Mail.MailAddress(ConfigurationManager.AppSettings["fromEmailAddress"]));
mailMessage.Subject = this.txtSubject.Text.Trim();
System.Text.StringBuilder html = new System.Text.StringBuilder("<html><head><title></title></head><body><table><tr><td>");
html.AppendFormat("From : {0}</td></tr><tr><td>Email : {1}</td></tr>", this.txtName.Text, this.txtEmail.Text);
//html.AppendFormat("<tr><td>{0}</td></tr></table><p>{1}</p></body></html>", Public.ToPersianDateTime(DateTime.Now), this.txtMessage.Text);
mailMessage.Body = html.ToString();
//mailMessage.Body = string.Format("<html><head></head><body><h1 style='color: red;'>Test HTML Email</h1></br>rr</body>");
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient();
try
{
smtpClient.Send(mailMessage);
Response.Redirect("~/Default.aspx");
}
catch (SmtpFailedRecipientsException recExc)
{
for (int recipient = 0; recipient < recExc.InnerExceptions.Length - 1; recipient++)
{
System.Net.Mail.SmtpStatusCode statusCode;
statusCode = recExc.InnerExceptions[recipient].StatusCode;
if ((statusCode == System.Net.Mail.SmtpStatusCode.MailboxBusy) || (statusCode == System.Net.Mail.SmtpStatusCode.MailboxUnavailable))
{
smtpClient.Send(mailMessage);
}
else
{
Server.Transfer("~/Error.aspx");
}
}
}
}
}