Click here to Skip to main content
15,898,628 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 :

VB
Try
           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.gmail.com"
           smtp.Port = 587
           smtp.EnableSsl = True
           smtp.DeliveryMethod = SmtpDeliveryMethod.Network
           smtp.UseDefaultCredentials = False
           smtp.Credentials = New NetworkCredential("ahmad.bastas@gmail.com", "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())
           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


And this is what in the create user wizard :

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



So what is the error ?

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

try changing

VB
smtp.UseDefaultCredentials = False


to

VB
smtp.UseDefaultCredentials = True


and check this out:

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

hope it helps :)
 
Share this answer
 
Comments
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

VB
Dim SmtpClient As New Net.Mail.SmtpClient("smtp.gmail.com", 587 )
SmtpClient.EnableSsl = True 
'now provide network credential
smtp.Credentials = New NetworkCredential("ahmad.bastas@gmail.com", "password")
 
Share this answer
 
v2
Comments
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