Hi I am trying to send an email using Rebex Smtp SendDirect and I get this error:
SendEmail: Rebex.Net.SmtpException: Client was not authenticated (530).
at Rebex.Net.Smtp.WCB(String A, String B)
at Rebex.Net.Smtp.ADB(String A, String[] B, String C, Stream D, TransferEncoding E)
at Rebex.Net.Smtp.GDB(MimeMessage A, Stream B, MailAddress C, MailAddressCollection D)
at Rebex.Net.Smtp.SendDirect(MimeMessage message)
at Rebex.Net.Smtp.SendDirect(MailMessage message)
My code:
Dim myMail As New Rebex.Mail.MailMessage
Try
myMail.From = "myname@myCompany.com"
myMail.Subject = "Test"
myMail.BodyText = "Blah blah"
myMail.To = "myname@myCompany.com"
myMail.Attachments.Add(New Rebex.Mail.Attachment(filePath))
myMail.Priority = Rebex.Mail.MailPriority.Normal
Smtp.SendDirect(myMail)
Catch ex As Rebex.Mail.MailException
Catch ex As System.Exception
Finally
End Try
Notice that sender's and receiver is the same email address. The company uses an Exchange server.
When I put as receiver's email address my gmail address the code works fine.
What I am doing wrong?
the Smtp.SendDirect method is used to deliver the email to the recipient's actual SMTP server. If you get "Client was not authenticated" error message when trying to send the email directly to the recipient's SMTP server it suggests that the company's Exchange server was configured to not receive email for the user without authentization to the Exchange server. This is definitely a strange behavior of a SMTP server as it effectively disallows anyone 'strange' to send email to "myname@myCompany.com" connecting directly to the SMTP server. So the problem is probably in the Exchange server configuration.
If you change the receiver to your GMail address, the Rebex Secure Mail Smtp.SendDirect method connects directly to GMail SMTP server and the behaviour might really be different.
If you want to send email from and to the same address ("myname@myCompany.com")and the server requires authentization (which is your case), try the following code which should work with your Exchange server - assuming you have the credentials for the user:
Dim smtp As New Smtp()
smtp.Connect("myCompany.com")
smtp.Login("myname", "password")
Dim myMail As New Rebex.Mail.MailMessage
myMail.From = "myname@myCompany.com"
myMail.Subject = "Test"
myMail.BodyText = "Blah blah"
myMail.To = "myname@myCompany.com"
myMail.Attachments.Add(New Rebex.Mail.Attachment(filePath))
myMail.Priority = Rebex.Mail.MailPriority.Normal
smtp.Send(myMail)
smtp.Disconnect()