如何识别用户发送的邮件是否正确?

本文关键字:是否 何识别 识别 用户 | 更新日期: 2023-09-27 17:49:43

我是从。net应用程序发送邮件,我的邮件代码工作正常,但我不想允许不正确的邮件id。那么我如何识别发送邮件的用户是否有正确的id呢?

我想知道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;
    } 

如何识别用户发送的邮件是否正确?

我将使用正则表达式来验证电子邮件。

http://www.codeproject.com/KB/recipes/EmailRegexValidator.aspx

至于捕获smtp响应,这个链接应该会对您有很大帮助。只要看看回应部分,很明显你知道介绍项目。

http://www.csharphelp.com/2007/01/howto-smtp-in-c/