SMTP Authentication

Visual Basic Code | ASP Code

The sample sends simple e-mail using SMTP authentication.

Many mail servers allow sending e-mails from authenticated users only. To authenticate, you need to specify your user account name, the password and the authentication method.

Authentication methods can be of two types: secure (password is transmitted to the server in secure format) and insecure (password is transmitted as plain-text). Many SMTP servers support insecure methods only.

SMTP object supports several authentication methods (both secure and insecure) through AuthMethod property. Some of them may be not supported by particular SMTP server.

[Visual Basic]:

Dim objSMTP, strTemp

' Create mailer component
Set objSMTP = CreateObject("MailBee.SMTP")

' Unlock SMTP component
objSMTP.LicenseKey = "put your license key here"

' Set SMTP server name
objSMTP.ServerName = "mail.server.com"

' Use LOGIN Authentication method (insecure, but
' supported by nearly all SMTP servers)
objSMTP.AuthMethod = 2

' Set authentication credentials
objSMTP.UserName = "jdoe"
objSMTP.Password = "secret"

' Set message properties
objSMTP.FromAddr = "sender@firstdomain.com"
objSMTP.ToAddr = "recipient@seconddomain.com"
objSMTP.Subject = "Test"
objSMTP.BodyText = "Body of the test message"

' Try to send message
If objSMTP.Send Then
  MsgBox "Sent successfully"
Else
  MsgBox "Error #" & objSMTP.ErrCode & ", " & objSMTP.ErrDesc
End If

[ASP]:

Dim objSMTP, strTemp

' Create mailer component
Set objSMTP = Server.CreateObject("MailBee.SMTP")

' Unlock SMTP component
objSMTP.LicenseKey = "put your license key here"

' Set SMTP server name
objSMTP.ServerName = "mail.server.com"

' Use LOGIN Authentication method (insecure, but
' supported by nearly all SMTP servers)
objSMTP.AuthMethod = 2

' Set authentication credentials
objSMTP.UserName = "jdoe"
objSMTP.Password = "secret"

' Set message properties
objSMTP.FromAddr = "sender@firstdomain.com"
objSMTP.ToAddr = "recipient@seconddomain.com"
objSMTP.Subject = "Test"
objSMTP.BodyText = "Body of the test message"

' Try to send message
If objSMTP.Send Then
  Response.Write "Sent successfully"
Else
  Response.Write "Error #" & objSMTP.ErrCode & ", " & objSMTP.ErrDesc
End If
See Also:
AuthMethod Property

 


Send feedback to AfterLogic
Copyright © 2002-2024, AfterLogic Corporation. All rights reserved.