Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all ,

For 3 days i have been searching on google and trying every provided solution but nothing worked for me.I am sending an email through gmail in asp.net.The email is being sent and received by the receiver.But after it is sent the asp.net is generating this error :

VB
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. p18sm4404756wbh.38


And here is my code that is written on sending email event for create user wizard :

VB
Public Sub CreateUserWizard1_SendingMail(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MailMessageEventArgs) Handles CreateUserWizard1.SendingMail
        Try
            Dim user As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName.ToString())
            Dim userId As Guid = DirectCast(user.ProviderUserKey, Guid)
            Dim smtp As New SmtpClient()
            e.Message.IsBodyHtml = True
            e.Message.Subject = "Allo Magazine : Registration Confirmation Email"
            e.Message.Body = e.Message.Body.Replace("<%AC%>", userId.ToString())
            smtp.Host = "smtp.gmail.com"
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network
            smtp.UseDefaultCredentials = False
            smtp.Port = 587

            smtp.EnableSsl = True
            smtp.Credentials = New NetworkCredential("[DELETED]@gmail.com", "password")
            
            smtp.Send(e.Message)
            'after all of this happens we take the querystring when user presses on activation link and then see if he is not approved we approve him

        Catch ex As Exception
            Response.Write(ex.Message)

        End Try

    End Sub


Also i have this mail definition in the create user wizard :

XML
<MailDefinition Priority="High" BodyFileName="~/ConfirmationEmailHTML/ConfirmationEmail.htm"
                        Subject="Allo Magazine : Registration Confirmation Email" From="[DELETED]@gmail.com">
                    </MailDefinition>



And this is what in the web.config.

XML
<system.net>
  <mailSettings >
    <smtp deliveryMethod="Network" from="[DELETED]@gmail.com"   >
      <network defaultCredentials="false" host="smtp.gmail.com"  port="587"  userName="[DELETED]@gmail.com" password="password" />
    </smtp>
  </mailSettings>
</system.net>


Please help me guys,i am about to loose my job.


[edit]Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know - OriginalGriff[/edit]
Posted
Updated 29-Aug-11 22:33pm
v4
Comments
mhamad zarif 30-Aug-11 4:45am    
Thanks. for your help.But actually the last thing that i care about now is spams.Le my email burn.I only care now about solving this problem before getting fired.So please and since you have a great experience.Can you help me in solving this problem ?

1 solution

hey,
did you checked this link :

http://zeemalik.wordpress.com/2009/02/18/the-smtp-server-requires-a-secure-connection-or-the-client-was-not-authenticated/[^]

I think this can help you out.

Specifically it says : An important point to note is that you have to set the EnableSSl to True before you set the NetWork Credentials of your SMTP client.

Anurag
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900