Connect Method


Connects to the SMTP server, sends hello and optionally authenticates the client.

Make sure to set at least the following properties before calling this method:

In most cases, you'll also need to use ESMTP authentication (EHLO command), also set AuthMethod and UserName/Password properties before calling Connect method. You'll not need this only if your server allows anonymous senders to relay e-mail which is quite uncommon nowadays.

It's not required to call this method in order to connect to SMTP server (though it's recommended). Methods of SMTP object (such as Send, SendEx, RelayMessage) automatically call it if the connection is not established.

With NTLM and GSSAPI authentication, you may also want to set UserDomain property. Also, GSSAPI/Kerberos method allows setting TargetName (SPN).

If you're using Integrated Windows Authentication (IWA), you may leave UserName and Password blank but must set AuthMethod property to use IWA-compatible authentication method.

Note: If ESMTP authentication is not used (AuthMethod=0), connection procedure starts with "HELO Your domain" command. You can specify "Your domain" explicitly using Domain property. If Domain property is empty, host name of the machine running MailBee will be used as a domain.

Domain and UserDomain properties have different meaning. UserDomain is used during authentication (NTLM or GSGAPI), UserDomain is linked with UserName property. Domain property, however, is used when the client says hello to the server and its value is should be the host name of the client (MailBee machine).


blnResult = ObjectName.Connect  
Parameters: None 
Return value As Boolean True if successful, False if connect procedure failed (mail server is not responding, username and/or password is incorrect, authentication method is not supported, license key is invalid). You may check ErrDesc property or log file to get more detailed error information  

Usage example:

Dim Mailer
'Using visual basic to create object
Set Mailer = CreateObject("MailBee.SMTP")
'Using ASP to create object
'Set Mailer = Server.CreateObject("MailBee.SMTP")
'In ASP use Response.Write instead of MsgBox
Mailer.LicenseKey = "put your license key here"
Mailer.ServerName = "mail.server.com"
Mailer.UserName = "MyName"
Mailer.Password = "MyPassword"
Mailer.AuthMethod = 1 ' PLAIN ESMTP authentication
If Mailer.Connect Then
  Mailer.Message.ToAddr = "bill@yoursite.com"
  Mailer.Message.FromAddr = "joe@mysite.com"
  Mailer.Message.Subject = "Hello"
  Mailer.Message.ImportBodyText "C:\docs\letter.htm", True
  Mailer.Send
  Mailer.Disconnect
Else
  ' Server not available, PLAIN is not supported or username/password is incorrect
  MsgBox Mailer.ErrDesc 
End If

See Also:

ServerName Property
Domain Property
Message.FromAddr Property
PortNumber Property
UserName Property
Password Property
AuthMethod Property
Disconnect Method


Copyright © 2002-2022, AfterLogic Corporation. All rights reserved.