0 votes
by (210 points)
edited

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?

Applies to: Rebex Secure Mail

2 Answers

0 votes
by (58.9k points)
edited
 
Best answer

Hi,

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 your 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.

If you change the receiver to your gmail address, the Rebex Smtp.SendDirect method connects to GMail SMTP server and the behaviour might really be different.

If you want to use email from and to the same address ("myname@myCompany.com") I guess the following code 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()
+1 vote
by (210 points)
edited

The problem is that I want to use the SendDirect method to avoid the login.
So the solution was (for Exchange Server 2010) :

Please verify if you have allowed Anonymous connection from default receive connector.
1.Expand Server Configuration, click Hub Transport, and in the work pane under the Receive Connectors tab, select the Default <server name=""> connector. In the action pane, click Properties.
2.In <connector> Properties, select the Permissions tab.
3.Select Anonymous Users to add anonymous permissions. Click OK.

The solution was found here

Thank you very much Tomas

...