1

I've got an emailing system in my application which I have used fine and have seen it working.

The customer has also managed to send emails using the program, however, once they've paid for the application, they're then selling it on to other customers.

They've just taken it in to test with the first customer and they're having troubles sending emails, so I investigated the error log and saw the following message:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [BN6PR2201CA0027.namprd22.prod.outlook.com]

Now, after Googling this exact error message, the top result was this question, in which it's clear to see that the OP was trying to send a message from an email address that was hard-coded as "emailaddress". However, that isn't the case for me.

My code is as follows:

  recipient = eMail

        Smtp_Server.UseDefaultCredentials = False
        Smtp_Server.Credentials = New Net.NetworkCredential(senderAdd, senderPass)
        Smtp_Server.EnableSsl = False
        Smtp_Server.Host = SMTPserver

        AddHandler Smtp_Server.SendCompleted, AddressOf sendComplete

    e_mail = New MailMessage()
    e_mail.From = New MailAddress(senderAdd)
    e_mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess
    e_mail.To.Add(eMail)
    e_mail.Subject = subj
    e_mail.IsBodyHtml = False
    e_mail.Body = bod

 Smtp_Server.SendAsync(e_mail, userState)

Is there anything in here which would be causing this error? If so, what is it? The variables are all set from a database table, and if there are any null values then the system will pop a message box to alert the user of this and then exit the subroutine and not send the email, so it's not an issue with null values - The only thing I can think of is that the credentials are wrong, but they've supposedly been verified by 3 different people as correct.

David
  • 2,298
  • 6
  • 22
  • 56
  • Since the exception mentioned requiring a secure connection, did you try to enable SSL? "Smtp_Server.EnableSsl = True" (the SSL may run on a different port, I route my mail through gmail on my web-site and the SSL requires the port to be set also). – b.pell Jun 07 '17 at 19:56

1 Answers1

0

You might need to specify the domain. Use this constructor of the NetworkCredential class and pass in the domain.

Smtp_Server.Credentials = New Net.NetworkCredential(senderAdd, senderPass, "expectedDomainName")

Difficult to say for sure though because we can't reproduce this issue under your same conditions.

NoAlias
  • 9,218
  • 2
  • 27
  • 46