Client Authentication | ||
In some cases a mail server may require that the client authenticate itself before it is permitted to submit a message for delivery. This is typically done as an anti-spam measure to ensure that only authorized users are able to send messages. Authentication is part of the Extended SMTP (ESMTP) standard, so to use this feature it is required that you set the Extended property to True, and then call the Authenticate method after the connection has been established. For example: SmtpClient1.Extended = True nError = SmtpClient1.Connect(strHostName) If nError Then MsgBox SmtpClient1.LastErrorString, vbExclamation Exit Sub End If If SmtpClient1.Extended = False Then MsgBox "This server does not support authentication", vbInformation SmtpClient1.Disconnect Exit Sub End If nError = SmtpClient1.Authenticate(strUserName, strPassword) If nError Then MsgBox SmtpClient1.LastErrorString, vbExclamation SmtpClient1.Disconnect Exit Sub End If First, the Extended property is set to True, which tells the SMTP control that we would like to try and establish an ESMTP session. After the connection has been established, the value of the Extended property is checked to make sure that it is still True. Because ESMTP is an optional extension to the protocol, it is not required that all mail servers support it. The control will not return an error if the server doesn't support ESMTP, it will simply set the Extended property back to False, which lets the application know that the connection has been made, but no extended features are available. The Authenticate method expects two arguments, a username and password which are used to authenticate the client session. Once the session has been authenticated, the client can proceed to submit the message for delivery. |
||
Copyright © 2024 Catalyst Development Corporation. All rights reserved. |