0

EDIT: I'll add that the domain is hosted by Web.com. Perhaps someone else uses them and has experienced something similar.

The code below is set up for both my own smtp server and gmail. Both fail for different reasons. I'm writing this in VS 2010/.Net 4

When I send from my own domain smtp server I receive no exceptions I just never send any email. I have tried sending from different accounts to different accounts. There are no exceptions, is just never gets delivered. I changed my password and did receive and authentication error, which seems to prove I had the credentials correct. I am following my domain hosts instructions for domain name and port.

With gmail I get the error, "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at". I read about this and followed the links to allow less secure devices to access my gmail. I received the confirmation email from gmail indicating I had made the changes for less secure email, but I still get the same error.

I have read and tried everything at the following links and can't get past this.

http://ithoughthecamewithyou.com/post/sending-email-via-gmail-in-cnet-using-smtpclient

c# SmtpClient class not able to send email using gmail

http://blogs.msdn.com/b/mariya/archive/2006/06/15/633007.aspx

Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

When looking at the code I am using, does anything jump out at you and being not right? Is there a property set wrong or am I missing a Property?

Public Shared Sub SendMailMessage(ByVal sfrom As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, ByVal subject As String, ByVal body As String)
    Try
        Dim mMailMessage As New MailMessage()

        mMailMessage.From = New MailAddress(sfrom)
        mMailMessage.To.Add(New MailAddress(recepient))

        If Not bcc Is Nothing And bcc <> String.Empty Then
            mMailMessage.Bcc.Add(New MailAddress(bcc))
        End If

        If Not cc Is Nothing And cc <> String.Empty Then
            mMailMessage.CC.Add(New MailAddress(cc))
        End If

        mMailMessage.Subject = subject
        mMailMessage.Body = body

        mMailMessage.IsBodyHtml = True
        mMailMessage.Priority = MailPriority.Normal

    'GMAIL
        'Dim mSmtpClient As New SmtpClient()
        'mSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
        'mSmtpClient.UseDefaultCredentials = True
        'mSmtpClient.EnableSsl = True
        'mSmtpClient.Host = "smtp.gmail.com"
        'mSmtpClient.Port = 587
        'mSmtpClient.Credentials = New System.Net.NetworkCredential("my gmail address", "my password")
        'mSmtpClient.Send(mMailMessage)

    'MY DOMAIN
        Dim mSmtpClient As New SmtpClient()
        mSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
        mSmtpClient.UseDefaultCredentials = True
        mSmtpClient.EnableSsl = False
        mSmtpClient.Host = "smtp.mydomain.com"
        mSmtpClient.Port = 587
        mSmtpClient.Credentials = New System.Net.NetworkCredential("my full email address", "my password")
        mSmtpClient.Send(mMailMessage)
    Catch ex As Exception
        'HttpContext.Current.Response.Redirect("~\EmailError.aspx")
        MsgBox(ex.Message, MsgBoxStyle.Information)
    End Try
End Sub
Community
  • 1
  • 1
user1091524
  • 865
  • 1
  • 15
  • 28
  • you can not get exception with this code `MsgBox(ex.Message, MsgBoxStyle.Information)` !!! you are on server side now, just log error there... – Aristos Jan 21 '15 at 22:06
  • Msgbox is only for development. You'll notice I have commented out the redirect for when it is on the server. – user1091524 Jan 21 '15 at 22:09
  • Port 587 is used for both. Gmail uses SSL, My host explicitly says not to enable SSL. When I do I get an exception saying the site does not support secure connections. – user1091524 Jan 21 '15 at 22:11

1 Answers1

0

For gmail my password was too weak. Ugh! Why couldn't Google just tell me that instead of saying, "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"

It was an authentication error, so the message was accurate, just misleading. 6 hours of my life I'll never get back. Oh, plus the useless half hour I spent on the phone with Web.com support.

user1091524
  • 865
  • 1
  • 15
  • 28
  • I answered too soon. SmtpClient works from my local, development machine, but fails on the server for smtp.gmail.com. I think because the gmail ssl cert is not on the web.com server. Getting it on there would probably take an act of congress. – user1091524 Jan 22 '15 at 17:20
  • 4 calls to web.com support didn't clear it up, but gave me enough information to get it running. One person finally found that I should use the internal smtp server mailhub.registeredsite.com when sending from my site. They told me I didn't need a port number, but obviously that is wrong. Port 25 with no credentials works. Since it can only be accessed from their servers, it can't be used to spam from the outside world. – user1091524 Jan 23 '15 at 02:42