Checking the email address on the exchange server

I allow users to manage the mailing list stored in the database. Users are allowed to enter emails that are @ mydomain.com. The web application then accepts the mailing list and sends emails. I would like to confirm that the letter is valid before sending an email from the application.

To send an email, I use this code:

    Dim SendTo As String = "ThisIsNotARealEmailAddress@mydomain.com"
    Dim SentFrom As String = "me@mydomain.com"
    Dim MessageBody As String = "blah blah blah"
    Dim MessageSubject As String = "This is the subject"


    Dim mm As New MailMessage(SentFrom, SendTo)
    mm.Subject = MessageSubject
    mm.IsBodyHtml = False
    mm.Priority = MailPriority.High
    mm.Body = MessageBody

    Dim smtp As New SmtpClient()
    smtp.Send(mm)

If SendTo is not a valid email address, the server returns this error:

Mailbox unavailable. The server response was: 5.1.1 <ThisIsNotARealEmailAddress@mydomain.com>... User unknown

Is it still necessary to check email when an email address is added to the database instead of a block try catchwhen sending an email?

+3
1

? ? Windows? AD AD, . ? , Windows, -.

+2

Source: https://habr.com/ru/post/1773935/


All Articles