I am sending mail from .net application, my mail code is working fine but I dont want to allow the incorrect mail id's. So how can I recognize whether the user who sent the mail has the correct id or not开发者_JAVA技巧.
And i want to know the response of the mail which has been sent by the smtpclient.
Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
MailSettingsSectionGroup settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
smtpHost = settings.Smtp.Network.Host;
smtpport = settings.Smtp.Network.Port.ToString();
smtpuser = settings.Smtp.Network.UserName;
smtppwd = settings.Smtp.Network.Password;
string MessageBody = string.Empty;
try
{
message = new MailMessage();
message.From = new MailAddress(smtpuser);
message.To.Add(toMailAddress);
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = mailSubject;
message.Body = mailMessage.ToString();
message.IsBodyHtml = true;
client = new SmtpClient();
client.Host = smtpHost;
//if (isSSLEnabled)
//{
// client.EnableSsl = true;
//}
client.Port = Convert.ToInt32(smtpport);
client.EnableSsl = false;
client.Credentials = new System.Net.NetworkCredential(smtpuser, smtppwd);
client.Send(message);
}
catch (Exception ex)
{
string x = ex.Message;
}
I would use a regular expression to validate the email.
http://www.codeproject.com/KB/recipes/EmailRegexValidator.aspx
As for the capturing the smtp response, this link should help you out greatly. Just check out the response section, its obvious you know the introduction items.
http://www.csharphelp.com/2007/01/howto-smtp-in-c/
精彩评论