1
我從.net應用程序發送郵件,我的郵件代碼工作正常,但我不想允許不正確的郵件ID。那麼如何才能識別發送郵件的用戶是否具有正確的ID。如何識別用戶發送的maild是否正確?
我想知道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;
}
你是什麼意思的「郵件ID」?我在代碼中看不到任何類似ID的東西。你的意思是「電子郵件地址」,還是你的意思是不同的? – 2011-04-12 14:26:24
@Joe White很確定smtpuser/toMailAddress是一個包含電子郵件地址的字符串。你能驗證OP嗎? – clamchoda 2011-04-12 14:29:02