如何强制SMTPClient进行身份验证

时间:2013-11-01 15:18:13

标签: c# .net smtp

我有一个smtp服务器,不需要身份验证来发送电子邮件,我使用C#的SmtpClient:

        message.From = new MailAddress(appSettings.senderMail);      
        message.Subject = appSettings.mailsubj;
        message.Body = appSettings.mailbody;
        Attachment attach = new Attachment(sOutput);
        message.Attachments.Add(attach);

        SmtpClient client = new SmtpClient(appSettings.SMTP, appSettings.smtpSvPort);
        if (bSMTPAuth)
        {
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential(strSMTPUsername, strSMTPPAssword);
        }

        client.SendCompleted += this.SendCompletedCallback;
            message.To.Clear();
            message.To.Add(clientEmail);
            client.Send(message);

它可以在没有身份验证的情况下发送,但是当我尝试进行身份验证时,即使我使用了不正确的密码,邮件仍然会被发送,我想查看身份验证是否有效..并且当我连接错误时抛出并出错用户名/密码。

0 个答案:

没有答案