UserName Property


User name for ESMTP authentication.

Data Type: String

Remarks

For Exchange Server (Web Service or WebDAV protocol), if your application is Windows Service or Web Application, please set domain\user to UserName property to do user authentication.

Most SMTP servers require user authentication for anti-spam policy.

Example

[VB, VC++, Delphi] To get the full samples of EASendMail, please refer to Samples section.

[VB, VBA - SMTP User Authentication]

Const ConnectNormal = 0
Const ConnectSSLAuto = 1
Const ConnectSTARTTLS = 2
Const ConnectDirectSSL = 3
Const ConnectTryTLS = 4

Const AuthAuto = -1
Const AuthLogin = 0
Const AuthNtlm = 1
Const AuthCramMd5 = 2
Const AuthPlain = 3
Const AuthMsn = 4
Const AuthXoauth2 = 5

Private Sub SendEmail()
  Dim oSmtp As EASendMailObjLib.Mail
  Set oSmtp = New EASendMailObjLib.Mail
  
  oSmtp.LicenseCode = "TryIt"

  ' Your SMTP server address
  oSmtp.ServerAddr = "smtp.emailarchitect.net"
  
  ' User and password for ESMTP authentication
  oSmtp.UserName = "test@emailarchitect.net"
  oSmtp.Password = "test"

  ' Use default authentication mechanism
  ' This is default value, you don't have to add this line
  oSmtp.AuthType = AuthAuto
  
  ' ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically
  oSmtp.ConnectType = ConnectTryTLS

  oSmtp.FromAddr = "test@emailarchitect.net"
  oSmtp.AddRecipient "Support Team", "support@adminsystem.com", 0
  
  oSmtp.UserName = "test@adminsystem.com"
  oSmtp.Password = "test"
  
  oSmtp.BodyText = "Hello, this is a test...."
  If oSmtp.SendMail() = 0 Then
    MsgBox "Message delivered!"
  Else
    MsgBox oSmtp.GetLastErrDescription()
  End If
End Sub


[VBScript, ASP - SMTP User Authentication] Const ConnectNormal = 0 Const ConnectSSLAuto = 1 Const ConnectSTARTTLS = 2 Const ConnectDirectSSL = 3 Const ConnectTryTLS = 4 Const AuthAuto = -1 Const AuthLogin = 0 Const AuthNtlm = 1 Const AuthCramMd5 = 2 Const AuthPlain = 3 Const AuthMsn = 4 Const AuthXoauth2 = 5 Dim oSmtp Set oSmtp = Server.CreateObject("EASendMailObj.Mail") oSmtp.LicenseCode = "TryIt" ' Your SMTP server address oSmtp.ServerAddr = "smtp.emailarchitect.net" ' User and password for ESMTP authentication oSmtp.UserName = "test@emailarchitect.net" oSmtp.Password = "test" ' Use default authentication mechanism ' This is default value, you don't have to add this line oSmtp.AuthType = AuthAuto ' ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically oSmtp.ConnectType = ConnectTryTLS oSmtp.FromAddr = "test@emailarchitect.net" oSmtp.AddRecipient "Support Team", "support@adminsystem.com", 0 oSmtp.UserName = "test@adminsystem.com" oSmtp.Password = "test" oSmtp.BodyText = "Hello, this is a test...." If oSmtp.SendMail() = 0 Then Response.Write "Message delivered!" Else Response.Write oSmtp.GetLastErrDescription() End If
[Visual C++ - SMTP User Authentication] #include "stdafx.h" #include <tchar.h> #include <Windows.h> #include "EASendMailObj.tlh" using namespace EASendMailObjLib; const int ConnectNormal = 0; const int ConnectSSLAuto = 1; const int ConnectSTARTTLS = 2; const int ConnectDirectSSL = 3; const int ConnectTryTLS = 4; const int AuthAuto = -1; const int AuthLogin = 0; const int AuthNtlm = 1; const int AuthCramMd5 = 2; const int AuthPlain = 3; const int AuthMsn = 4; const int AuthXoauth2 = 5; void SendEmail() { ::CoInitialize(NULL); IMailPtr oSmtp = NULL; oSmtp.CreateInstance(__uuidof(EASendMailObjLib::Mail)); oSmtp->LicenseCode = _T("TryIt"); // Your SMTP server address oSmtp->ServerAddr = _T("smtp.emailarchitect.net"); // User and password for ESMTP authentication oSmtp->UserName = _T("test@emailarchitect.net"); oSmtp->Password = _T("test"); // Use default authentication mechanism // This is default value, you don't have to add this line oSmtp->AuthType = AuthAuto; // ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically oSmtp->ConnectType = ConnectTryTLS; oSmtp->FromAddr = _T("test@emailarchitect.net"); oSmtp->AddRecipient(_T("Support Team"), _T("support@adminsystem.com"), 0); oSmtp->UserName = _T("test@adminsystem.com"); oSmtp->Password = _T("test"); oSmtp->BodyText = _T("Hello, this is a test...."); if(oSmtp->SendMail() == 0) { _tprintf(_T("email was sent successfully!\r\n")); } else { _tprintf(_T("failed to send email with the following error: %s\r\n"), (const TCHAR*)oSmtp->GetLastErrDescription()); } }
[Delphi - SMTP User Authentication] unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, EASendMailObjLib_TLB; // add EASendMail unit type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; const ConnectNormal = 0; ConnectSSLAuto = 1; ConnectSTARTTLS = 2; ConnectDirectSSL = 3; ConnectTryTLS = 4; AuthAuto = -1; AuthLogin = 0; AuthNtlm = 1; AuthCramMd5 = 2; AuthPlain = 3; AuthMsn = 4; AuthXoauth2 = 5; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var oSmtp : TMail; begin oSmtp := TMail.Create(Application); oSmtp.LicenseCode := 'TryIt'; // Your SMTP server address oSmtp.ServerAddr := 'smtp.emailarchitect.net'; // User and password for ESMTP authentication, oSmtp.UserName := 'test@emailarchitect.net'; oSmtp.Password := 'testpassword'; // This is default value, you don't have to add this line oSmtp.AuthType := AuthAuto; // ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically oSmtp.ConnectType := ConnectTryTLS; // Set your sender email address oSmtp.FromAddr := 'test@emailarchitect.net'; // Add recipient email address oSmtp.AddRecipientEx('support@emailarchitect.net', 0); // Set email subject oSmtp.Subject := 'simple email from Delphi project'; // Set email body oSmtp.BodyText := 'this is a test email sent from Delphi project, do not reply'; ShowMessage('start to send email ...'); if oSmtp.SendMail() = 0 then ShowMessage('email was sent successfully!') else ShowMessage('failed to send email with the following error: ' + oSmtp.GetLastErrDescription()); end; end.

See Also

User Authentication and SSL Connection

AuthType Property
Password Property