How to enable SSL for smtpclient when use Password Recovery control to send email

 I can send email with secure connection (SSL) in my program;

 

Web.config:

 

<system.net>

  <mailSettings>

   <smtp from="fromaddress">

    <network host="smtphm.sympatico.ca" password="password" userName="username" />

   </smtp>

  </mailSettings>

 </system.net>

 

----------------------------------

 

    Protected Sub SendEmail()

        '!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS

        Const ToAddress As String = "myaddress"

 

        '(1) Create the MailMessage instance

        Dim mm As New System.Net.Mail.MailMessage("from address", ToAddress)

 

        '(2) Assign the MailMessage's properties

        mm.Subject = "Test mail"

        mm.Body = "Body test "

        mm.IsBodyHtml = False

 

        '(3) Create the SmtpClient object

        Dim smtp As New System.Net.Mail.SmtpClient

 

        '(4) Send the MailMessage (will use the Web.config settings)

        Try

            smtp.EnableSsl = True

            smtp.Send(mm)

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

 

    End Sub

 

Above program works very well.

 

However, when I use password recovery, I will have Server Error showing below:

 

I think it is because a smtpclient not enable SSL in password recovery. But I can’t find nowhere to set enablessl to true.

 

Does anyone know how to fix it?

 

Thanks in advance.

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

 
[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]
   System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) +179
   System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) +70
   System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) +188
   System.Net.Mail.SmtpClient.Send(MailMessage message) +2184
   System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +482
   System.Web.UI.WebControls.PasswordRecovery.AttemptSendPasswordQuestionView() +744
   System.Web.UI.WebControls.PasswordRecovery.AttemptSendPassword() +106
   System.Web.UI.WebControls.PasswordRecovery.OnBubbleEvent(Object source, EventArgs e) +136
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +106
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +177
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3840

 

0
crestfernway
10/1/2006 2:58:57 PM
asp.net.security 27051 articles. 1 followers. Follow

4 Replies
920 Views

Similar Articles

[PageSpeed] 53

I have found a way to solve this problem myself to share with everybody.

 The main idea is that don't use System.Net.Mail.MailMessage to send password, intercapte the body, subject, to and from information and make your own message, then you can do what ever you want.

Protected Sub PasswordRecovery1_SendingMail(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MailMessageEventArgs) Handles PasswordRecovery1.SendingMail

'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS

Const ToAddress As String = "your email address"

'(1) Create the MailMessage instance

Dim mm As New System.Net.Mail.MailMessage("from address", ToAddress)

'(2) Assign the MailMessage's properties

mm.Subject = e.Message.Subject

mm.Body = e.Message.Body

'(3) Create the SmtpClient object

Dim smtp As New System.Net.Mail.SmtpClient

'(4) Send the MailMessage (will use the Web.config settings)

Try

smtp.EnableSsl =

True

smtp.Send(mm)

Catch ex As Exception

MsgBox(ex.Message)

End Try

'don't send the System.Net.Mail.MailMessage

e.Cancel =

True

End Sub
0
crestfernway
12/15/2006 9:28:09 PM
Hi crestfernway, I'm glad to see you've solved the problem by yourself. Thanks for sharing your experience with us, which will help others with similar issue.

The future is now...
Sincerely,
LeiJun Jie
Microsoft Online Community Support
0
Leijun
1/8/2007 7:02:34 AM

I tried the solution, but still no luck.

I pasted it and just changed the e-mail address, but I get this error:

http://xs412.xs.to/xs412/07081/xbcb.PNG

0
Susan_M
2/19/2007 1:57:31 AM

You are awesome, that worked.  Thank You! 

 Might suggest this addition:
        MailAddress  maTo    = new MailAddress(e.Message.To.ToString()),
                            maFrom  = new MailAddress(e.Message.From.ToString());
 

        //(1) Create the MailMessage instance
        MailMessage mm = new MailMessage( maFrom, maTo);

.... 

0
sobelito
9/6/2007 9:22:01 PM
Reply:

Similar Artilces:

using password recovery control connect to memershiprovider and send password as email
hi,  this is my first question in this forum and its urgent -please help.   I am new to asp.net 2.0 and I am supposed to create a web page using password recovery control and and when the user enters a user id -(which in my application is an email id) I should connect to the Membership provider that I created in web.config and then retreive the password from database and using smtp mail server I should email that password to that user's email.   how do i acheive it- I saw lot of examples but they r not clear- please can anyone give me a live example of how this is done. ...

Unable to use Password Recovery control to send email with Gamil SMTP.
I need to send the password recovery email using SMTP server of Gmail. Since, Gmail requires enableSsl to be set to true, I can't set the mail settigs in web.config like :- <system.net>    <mailSettings>      <smtp from="usernme@gmail.com">        <network host="smtp.gmail.com" port="587" userName="username" password="mypassword" defaultCredentials="false"></network>      </smtp>  &nb...

How not to use security question and password in the Password Recovery control?
How not to use security question and password in the Password Recovery control? Thanks. You can turn in off in your web.config by setting the Membership provider's requiresQuestionAndAnswer attribute to false. You can for example update the membership in the machine.config or add a new provider to your web.config.  <membership>            <providers>                <add name="AspNetSqlMembershipProvider"      &...

Why do Sending SMTP Authenticated E-mail succeed using SmtpMail.Send() function but fail using SmtpClient.send() function ? Bugs in System.Net.Mail.SmtpClient when send a Authenticated E-mail?
I click btnOK button, the email can send OK, but click btnFail button,  the following error is displayed! why ? you can test the section code. The SMTP, username, password are valid!  Many thanks! "Syntax error, command unrecognized. The server response was: authentication failed,decode user password error" I have tested some other SMTP, somes is OK. I think there are some bugs with System.Net.Mail.SmtpClient when send a Authenticated E-mail with some SMTP!   //------------------------------------------.ASPX Code----------------------------------------...

password recovery control and enabling SSL?
I'm writing a website where users can retrieve their passwords--or change them for that matter--using .net 2.0's built in controls (so password recovery control and password change control). But the trouble I'm having is configuing the SMTP to connect to gmail and I'm pretty sure the problem is that SSL i not enabled. I know how to solve this if im using an SMTPclient--just enable ssl in the code, but since the password controls are using something built in, they are relying on the web.config. And there I can't seem to find a way to enable SSL. I've also tried to play...

Password Recovery control
Hi,I am using the Password Recovery control and have given all my users my email address at work and everything works fine.  As soon as I give them another email address eg. a Yahoo address, then I get the following error message - SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for xyz@yahoo.com I would appreciate any help.  Many thanks in advance.Polly Anna That could means your outgoing e-mail server requires authentication.Cheers,       Kevin JonesMy Blog Thank you ...

Not able to send mail using password recovery control
 Hi,I'm using password recovery control to email my password to the email address stored in the system. But the control is unable to send email from my gmail account since SSL is enabled in gmail. So I tried setting up my own text file in custom format to send a message via SMTP. But I do not know how to retrieve the system generated password which gets automatically created when the user clicks the submit button. How do I get the value of this field and send via SMTP to my email? Thanks   do you try to configure the SMTP setting in your ASP.NET Configuration page ? On...

Password Recovery Control
Hi;I spent a lot of time looking for an answer on gloogle and here but everything i found didn't work for me.(I'm using VS 2005) I created a page with a PasswordRecovery control but everytime i put the username and click on the  button, i get this error: Mailbox name not allowed. The server response was: Sorry, that domain isn't in my list of allowed rcpthosts Here are the settings from my web.config: <system.net>  <mailSettings>     <smtp deliveryMethod="Network" from="info@mysite.com">     <network &n...

A problem to send email using Smtp
I have a proble to send an email from asp.net I do the following code to send an email: MailMessage mail=new MailMessage(); mail.From="test@server.com"; mail.To="myemailaddress@server.com"; mail.BodyFormat=MailFormat.Html; mail.Subject="testing..."; mail.Body="cool"; SmtpMail.SmtpServer="localhost"; SmtpMail.Send(mail); But I dont' receive an email when I use this method. Why is that? How can I send an email? Thanks in advance! check and see if.. -your client-side code has no errors -you imported the S...

How to use Forgot Password and Password Recovery Control
I want a basic functionality of Forgot Password. Like user enters his username and user should get a link where user can change his new password and i dont want the user to put old password. Just enter new password and submit and user's new password got saved in system. Also on clicking of Forgot Password Button how to send a mail and how to design the link i mean in what format , that we need to send to user in email. Thirdly i just tried to send a simple mail on click of forgot password button from my local development machine. My machine does not have any outlook or mail server set...

Sending Recovery Password Email From Recovery Wizard.
I am trying to give the option to send an email to users who forgot their passwords. My smpt setting are defined in the Web.Config File     <add key="smtp_email" value="smtp.sbcglobal.yahoo.com"/>    <add key="smtp_email_username" value="myvalue/>    <add key="smtp_email_password" value="mypassword"/>    <add key="smtp_port" value="25"/> what should the code look like from the VB or C# on the code behind page in the send mail event ...

i am using login controls in vidual dev 2005 .net 2 and want to send an email... however
even though i have added this to we.config <system.net>    <mailSettings>      <smtp deliveryMethod="PickupDirectoryFromIis"/>    </mailSettings>  </system.net> it is not working. How do i enable the local SMTP server. I have looked in IIS and it is ticked use localhost port 25. Authentication settings set to NOT REQUIRED. Is all this correct? Can anyone help Define what you mean by "not working."  Check SMTP logs.  Test SMTP with Outlook or another client.  And te...

Problem in sending new password by password recovery control
Password recovery control gives me a message that a new password has been sent but when i open my inbox i find no messages, i have tried alternative email accounts but it dosen't work. Hi Make sure you have config the SMTP server and it sends email with out problem. <system.net> <mailSettings> <smtp from=test@company.com> <network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" /> </smtp&...

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Web resources about - How to enable SSL for smtpclient when use Password Recovery control to send email - asp.net.security

Full Featured Email using powershell
... this is a fairly simple, however not quite so well explained – at least that i could find – process. Let us start simply, with the basic SMTPClient ...

Code - eventmachine/eventmachine - Code Climate
Get these same great results for any of your GitHub Repos. 100% free for Open Source, forever Code Climate Login Sign Up with GitHub Pricing ...

Setting of Google Gmail (IMAP, SMTP and POP3) - Coders Grid
Coders Grid your best development resources collections site Menu Skip to content Resource web development design stuffs guideline coding mobile ...

jQuery Contact Tabs Plugin « Design Chemical – jQuery, Wordpress, Tutorials & Plugins
jQuery Contact Tabs Plugin - Create slide out or static contact tabs with customised forms

Sample C# code for SMTP Email - EasySMTP
Send C# email via SMTP with this C# sample code from Easy-SMTP

Ginktage - A technology and Programming Blog on .NET , Delphi , SQL Server and Microsoft related technologies ...
... , Windows Mobile , Android , iOS development using If you need to send emails via SMTP programmatically using C# , you can use the the SmtpClient ...

Private Sub emailTeacher() Try Dim Server As New SmtpClie - Pastebin.com
PASTEBIN - #1 paste tool since 2002 create new paste tools api archive faq PASTEBIN create new paste trending pastes sign up login my alerts ...

CodeSOD: Patterned After Success
... Which is why Andres was getting null reference exceptions when trying to get an instance from this “singleton”. public class SingletonSmtpClient ...

Simple TLS/SSL SMTP client for Qt5 - Rastro-Mania - Coding and Engineering
Projects and tutorials in computer programming and electronics engineering

IIS7 - post #23 - Vista and SMTP server. Where is it?
Where is my SMTP server on Vista? I'm not sure why more developers haven't asked this question. Simple, it is not included - http://blogs.i ...

Resources last updated: 12/14/2015 4:56:30 AM