The SMTP server requires a secure connection or the client was not authenticated

本文描述了一个使用Gmail作为SMTP服务器发送邮件时遇到的问题:服务器要求安全连接或客户端未认证。文章提供了错误详细信息及解决方案,包括设置SmtpClient.EnableSsl为True,并通过覆盖CreateUserWizard的默认邮件发送功能来解决。

From: http://forums.asp.net/t/1199382.aspx

 

heelo, i have a register.aspx file. When i am going to complete the registration i get an error

Register.aspx code

 

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" CancelDestinationPageUrl="~/error.htm"
        CompleteSuccessText="Your account has been successfully created.You can now log in"
        ContinueDestinationPageUrl="~/Default.aspx" DisplayCancelButton="True" DuplicateUserNameErrorMessage="This username already exists.Please enter a different user name."
        FinishDestinationPageUrl="/Default.aspx" Font-Size="10pt" SkipLinkText="Skip" MailDefinition-BodyFileName="~/registration.txt" MailDefinition-From="mygmailname@gmail.com" MailDefinition-Priority="High" MailDefinition-Subject="Activate your WebSite Account" MailDefinition-IsBodyHtml="true" Width="310px" LoginCreatedUser="False"  >
        <WizardSteps>
            <asp:CreateUserWizardStep runat="server">
            </asp:CreateUserWizardStep>
            <asp:CompleteWizardStep runat="server">
            </asp:CompleteWizardStep>
        </WizardSteps>
        
        
    </asp:CreateUserWizard>

 Web.Config

	<mailSettings>
			<smtp from="mygmailname@gmail.com">
    <network host="smtp.gmail.com"  userName="mygamailname@gmail.com" password="mypass" defaultCredentials="true" />
   </smtp>
		</mailSettings>

 

Error I get

Server Error in '/' Application.
--------------------------------------------------------------------------------

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first j12sm16503842fkf.6 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first j12sm16503842fkf.6

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first j12sm16503842fkf.6]
   System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) +849368
   System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) +39
   System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) +95
   System.Net.Mail.SmtpClient.Send(MailMessage message) +2004
   System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +341
   System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() +571
   System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) +105
   System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +453
   System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +149
   System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +17
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.312; ASP.NET Version:2.0.50727.833 

 Help

Thank you in Advance

 

====================

If you're sending email through an SSL SMTP like GMail, then you have to set the SmtpClient.EnableSsl to True.  About the only way to do this is to override the email functionality of CreateUserWizard.  Use the SendingMail event method to define your MailMessage and SmtpClient and then use the Cancel property to prevent the CreateUserWizard from sending its automated email.
====================

You can refer to some of my previous posts

http://forums.asp.net/p/1156294/1899489.aspx#1899489 

http://forums.asp.net/p/1144253/1848821.aspx#1848821 

http://forums.asp.net/p/1117050/1736785.aspx#1736785 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值