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

I am sending a registration confirmation email to the user after he registers.The email is being sent through gmail smtp.But an error is generated after that and it is :
The SMTP server requires a secure connection or the client was not authenticated.
This is the code :

           Dim user As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName.ToString())
           Dim userId As Guid = DirectCast(user.ProviderUserKey, Guid)
           Dim smtp As New SmtpClient()

           smtp.Host = ""
           smtp.Port = 587
           smtp.EnableSsl = True
           smtp.DeliveryMethod = SmtpDeliveryMethod.Network
           smtp.UseDefaultCredentials = False
           smtp.Credentials = New NetworkCredential("", "password")
           ' Set MailMessage fields.
           e.Message.IsBodyHtml = True
           e.Message.Subject = "Allo Magazine : Registration Confirmation Email"
           ' Replace placeholder text in message body with information
           ' provided by the user.
           e.Message.Body = e.Message.Body.Replace("<%AC%>", userId.ToString())
           '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

       End Try

And this is what in the create user wizard :

<MailDefinition Priority="High" BodyFileName="~/ConfirmationEmailHTML/ConfirmationEmail.htm"
                       Subject="Allo Magazine : Registration Confirmation Email" From="">

So what is the error ?

Thanks in advance.
Updated 28-Aug-11 21:05pm

try changing

smtp.UseDefaultCredentials = False


smtp.UseDefaultCredentials = True

and check this out:

Sending E-mail using through Gmail account (Gmail SMTP Server account)[^]

hope it helps :)
Share this answer
mhamad zarif 29-Aug-11 3:14am    
Thanks for help.But it did not solve the problem.
Before you set the network credential set the SSl to true

Dim SmtpClient As New Net.Mail.SmtpClient("", 587 )
SmtpClient.EnableSsl = True 
'now provide network credential
smtp.Credentials = New NetworkCredential("", "password")
Share this answer
mhamad zarif 29-Aug-11 5:41am    
I already did that.Please check the code again.

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