dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Variable or ID?

  1. #1
    Join Date
    Sep 2014
    Posts
    48

    Variable or ID?

    Hello

    I have SMTP code that is giving me an authentication error although I have verified through PowerShell that my SMTP credentials are fine. So, I am tempted to think the error lies with my email variable. Basically, I have a form with one field whose ID in my aspx Web page is: strEmailTextBox. The user's email address, which can't be known, is the variable strEmailValue.

    My code in my aspx.vb page looks like this:

    Code:
    Dim myMessage As New MailMessage
    Dim Smtpserver As New SmtpClient
    Dim strEmailValue As String = Request.Form("strEmailTextBox")
    
    myMessage.From = New MailAddress("info@domain.net") 'Webmaster's email
    myMessage.To.Add(New MailAddress("strEmailValue")) 'user's email. 
    
    myMessage.Subject = ("Password Reset Request")
    myMessage.Body = "Please click on...."
    myMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
    myMessage.IsBodyHtml = True
    myMessage.Priority = MailPriority.High
    
    Smtpserver.DeliveryMethod = SmtpDeliveryMethod.Network
    Smtpserver.Host = ("IP address of SMTP server")
    Smtpserver.Port = 25
    Smtpserver.EnableSsl = False
    
    Dim basicAuthenticationInfo As New System.Net.NetworkCredential("info@domain.net", "SMTP_password")
    Smtpserver.Credentials = basicAuthenticationInfo
    Smtpserver.UseDefaultCredentials = False
    Smtpserver.Send(myMessage)
    
    myMessage.Dispose()
    myMessage = Nothing
    Smtpserver = Nothing
    The email field (stripped) in my aspx page is this:

    Code:
    <asp:TextBox ID="strEmailTextBox" runat="server" ></asp:TextBox>
    In the line I have highlighted above, I have the variable in there, but should I have the ID of the email field instead?

    Thank you.

    Steve

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,321

    Re: Variable or ID?

    myMessage.To.Add(New MailAddress("strEmailValue")) 'user's email.
    You have your variable name in quotes which means it will be treated as literal text and not as a variable
    So if the user entered MyAddress@SomeServer.Net the code would try to send to strUserEmailValue instead of
    MyAddress@SomeServer.Net

    Loose the quotes and it may be ok
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Sep 2014
    Posts
    48

    Re: Variable or ID?

    I will post back a little later after I have tried it (time difference) but that sounds promising. I would never have thought of it.

    I am grateful - fingers crossed!

  4. #4
    Join Date
    Sep 2014
    Posts
    48

    Re: Variable or ID?

    I am afraid that didn't work, DataMiser.

    The error is

    Mailbox unavailable. The server response was: Authentication is required for relay
    That error is misleading in my view because I can email from that SMTP server, with its credentials provided by my Web hosting service, to my own Microsoft email account via PowerShell. The difference with PS is that I type in the user's name myself (my own Microsoft Hotmail email account in the PS case), whereas in my vb.net case the code pulls in the user's email address from a form here:

    http://www.dimadayoub.net/forgot.aspx

    That's why I thought it may be a variable error.

    I have also pinged the IP address of the email server and it returns a 0% packet loss, so it is working.

    Seems a bit odd!

    Thank you anyway for explaining about the quotation marks.

    Steve

  5. #5
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,321

    Re: Variable or ID?

    I would suggest that you confirm what is in the variable at run time just to be sure that it does contain what it should when it gets to that point.

    You could also try using the email address that you got to work through PS as a literal just to see if that gives you the same error.
    If so then there maybe something that is not set properly with the SMTPClient.
    I personally have not tried to send email this way so have no real knowledge of it but sounds like there may be an option for authentication that needs to be set in order to send.

    In the case of a literal you would need to have it in quotes.
    myMessage.To.Add(New MailAddress("ActualAddress@Email.Net"))


    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Sep 2014
    Posts
    48

    Re: Variable or ID?

    I think it is now resolved.

    Once I got rid of this:

    Code:
    'Smtpserver.UseDefaultCredentials = False
                'Smtpserver.UseDefaultCredentials = True
    both of them, it was fine.

    But it does not generate a link for the user to click on to rest his pwd.

    I thought the server did that?

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)