dcsimg
Results 1 to 3 of 3

Thread: Sending email from webform using SMTP server

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    204

    Sending email from webform using SMTP server

    I have a ASP.NET web form for sending emails using SMTP. The hosting provider is 1and1. It worked for year. It stopped working several weeks ago. I receive the following error: "The SMTP server requires a secure connection or the client was not authenticated. The server response was: Authentication required"

    1and1 support is unable to explain the reason for the change. I would appreciate your help (see the VB.NET code below).

    I tried to change the port to 465 and 587, as well, I tried to change "EnableSsl" flag to true state - nothing worked. I wrote another code that works, but it allows to send an email with my email address in the "from" field (see the code below). But I would like to send an email with visitors' address in the "from" field.

    Code:
      ' code that worked once
       Dim mailMessage As New MailMessage()
       Dim MailAddress As String                        
       Try
           'creating an instance of the MailMessage class
           mailMessage.From = New MailAddress(txtEmail.Text)
           'senders email address
           mailMessage.To.Add("me@mysite.net")
           'recipient's email address
           mailMessage.Subject = "Form Submission: " & txtSubject.Text
           'subject of the email message
          mailMessage.IsBodyHtml = False
          'message text format. Can be text or html
          mailMessage.Body = txtName.Text & vbCr & txtEmail.Text
          'message body
          mailMessage.Priority = MailPriority.Normal
         'email priority. Can be low, normal or high
          Dim smtp As New SmtpClient("smtp.ionos.com")
         smtp.Port = 25
         smtp.EnableSsl = False
         smtp.Send(mailMessage)
         'using the static method "Send" of the SmtpMail class to send the mail
         Response.Write("Mail sent")
    Catch ex As Exception
        lblError.Text = "Form processing error occurred." & vbCr & "Please send your request to: me@mysite.net" 
    End Try
    
    ' code that is working today, but my email address must be in the "from" field
    
    Dim mailMessage As New MailMessage()
    Dim MailAddress As String           
    
    Try      
        'creating an instance of the MailMessage class
        mailMessage = New MailMessage()
        mailMessage.From = New MailAddress("me@mysite.net")
        'senders email address
        mailMessage.To.Add("me@mysite.net")
        'recipient's email address
        mailMessage.Subject = "Form Submission: " & txtSubject.Text
        'subject of the email message
        mailMessage.IsBodyHtml = False
        'message text format. Can be text or html
        mailMessage.Body = txtName.Text & vbCr & txtEmail.Text
        'message body
        mailMessage.Priority = MailPriority.Normal
        'email priority. Can be low, normal or high
        Dim smtp As New SmtpClient'("smtp.ionos.com")
        smtp.UseDefaultCredentials = False
        smtp.Credentials = New Net.NetworkCredential("me@mysite.net", "MyPassword")
        smtp.Host = "smtp.ionos.com"
        smtp.Port = 587
        smtp.EnableSsl = True
        smtp.Send(mailMessage)
        'using the static method "Send" of the SmtpMail class to send the mail
        Response.Write("Mail sent")
    Catch ex As Exception
        lblError.Text = "Form processing error occurred." & vbCr & "Please send your request to: me@mysite.net"
    End Try

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,733

    Re: Sending email from webform using SMTP server

    It sounds like you need to contact the SMTP provider in order to authorise the address you want to send from under the account you're using to log in.

  3. #3
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,427

    Re: Sending email from webform using SMTP server

    Note that if the visitor's address will be different every time you send an e-mail, JMCs idea may not be workable. However, it would also create a spam portal that users could send spam with, which is why 1and1 likely changed to require authentication to send email. A more detailed explanation of what you are using this for might be helpful. There may be other alternatives.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width