%Net.SMTP
class %Net.SMTP extends %Library.RegisteredObject
For information on using this class, see Sending and Receiving Email.
Send a SMTP mail messageThe Charset property of each %Net.MailMessagePart determines the charset for text MIME parts. The charset property is ignored unless ContentType=text/... Charset sets the Character Set for the content-type header. IMPORTANT: Charset must be set before any data is written to the TextData stream associated with this %Net.MailMessagePart. The Charset may also be initialized when the message is created by ##Class(%Net.MailMessagePart).%New(charset) or ##Class(%Net.MailMessage).%New(charset). For Unicode locale, the default Charset for ##Class(%Net.SMTP).%New() is utf-8.
  #include %occOptions
  #include %occStatus
  
  testmailsend3 ;
  ;  Replace information marked with [[ ]]
  
  new attached,err,m,nestedm,s,status
  set s=##class(%Net.SMTP).%New()
  set s.smtpserver=[["SMTP server name"]]
  set s.timezone=[["-0400"]]  may remove this line to get Universal Time
  set m=##class(%Net.MailMessage).%New()
  set m.From=[["test@company.com"]]
  // Either address with name or just email address supported.
  do m.To.Insert([["receiver@another.com"]])
  do m.To.Insert([["Joe Smith <jsmith@another.com>"]])
  write !,"s.port="_s.port
  write !,"s.localhost="_s.localhost
  set m.Subject="Sent by InterSystems IRIS mail"
  set m.Charset="iso-8859-1"
  set status=m.TextData.Write("This is the main body.")
  if $$$ISERR(status) do $system.OBJ.DisplayError(status) quit
  set status=m.TextData.Write($char(13,10))
  if $$$ISERR(status) do $system.OBJ.DisplayError(status) quit
  set status=m.TextData.Write("This is the second line.")
  if $$$ISERR(status) do $system.OBJ.DisplayError(status) quit
  set status=m.TextData.Write($char(13,10))
  if $$$ISERR(status) do $system.OBJ.DisplayError(status) quit
  set status=m.AttachFile("c:\winnt","notepad.exe")
  if $$$ISERR(status) do $system.OBJ.DisplayError(status) quit
  // Attach a text file with charset=iso-8859-1
  set status=m.AttachFile("d:\temp","test.txt",0,"iso-8859-1")
  if $$$ISERR(status) do $system.OBJ.DisplayError(status) quit
  set nestedm=m.AttachNewMessage()
  // Attach a binary file
  set status=nestedm.AttachFile("c:\irissys\bin","test.bin")
  if $$$ISERR(status) do $system.OBJ.DisplayError(status) quit
  write !,"m.Parts.Count()="_m.Parts.Count()
  write !,"m.Parts.GetAt(3).Parts.GetAt(1).FileName="_m.Parts.GetAt(3).Parts.GetAt(1).FileName
  write !,"m.Parts.GetAt(3).Parts.Count()="_m.Parts.GetAt(3).Parts.Count()
  set status=s.Send(m)
  if $$$ISERR(status) do $system.OBJ.DisplayError(status)
  quit
  
  
Property Inventory
- AllowHeaderEncoding
 - AuthFrom
 - ContinueAfterBadSend
 - Debug
 - Error
 - FailedSend
 - IPVersion
 - IgnoreFailedAuth
 - SSLCheckServerIdentity
 - SSLConfiguration
 - ShowBcc
 - Timeouts
 - UseSTARTTLS
 - authenticator
 - bufcount
 - localhost
 - port
 - smtpserver
 - timezone
 
Method Inventory
Parameters
Properties
0 - Try to connect with IPV4 first if failed then try it again with IPV6.
4 - Connect to SMTP server with IPV4 address.
6 - Connect to SMTP server with IPV6 address.
All other values are treated as 0.
By default, timeouts based on RFC 1123 guidelines are used.
The keys "EHLO", "HELO", "MAIL, "RCPT", "DATA", "AUTH", "STARTTLS", "QUIT", and "RSET" are supported to specify the timeout when waiting for a server response to the corresponding commands. The following special values are also supported:
- "_initial" - Set the timeout used when waiting for the initial greeting from the server
 - "_data termination" - Set the timeout used when waiting for the server response to the termination of the message data
 
Below is an example of how to use this property to configure the timeouts.
  set s=##class(%Net.SMTP).%New()
  set s.Timeouts("EHLO") = 100 ; use a 100s timeout when waiting for a response to the EHLO command
  set s.Timeouts("MAIL") = 200 ; use a 200s timeout when waiting for a response to the MAIL command
  
  #include %occOptions
  #include %occStatus
  
  authtestmailsend ;
  ;  Replace information marked with [[ ]]
  
  new auth,m,s,status
  set s=##class(%Net.SMTP).%New()
  set auth=##class(%Net.Authenticator).%New() ; use default authentication list
  set auth.UserName=[["myUser"]]
  set auth.Password=[["myPassword"]]
  set s.authenticator=auth
  set s.smtpserver=[["SMTP server name"]]
  set s.timezone=[["-0400"]]  may remove this line to get Universal Time
  set m=##class(%Net.MailMessage).%New()
  set m.From=[["test@company.com"]]
  do m.To.Insert([["receiver@another.com"]])
  do m.To.Insert([["Joe Smith <jsmith@another.com>"]])
  set m.Subject="Sent by InterSystems IRIS mail"
  set m.Charset="iso-8859-1"
  do m.TextData.Write("This message has been sent using an SMTP server with Authentication.")
  set status=s.Send(m)
  if $$$ISERR(status) do $system.OBJ.DisplayError(status)
  quit
  
  
Methods
"xtext" is formally defined as follows:
xtext = *( xchar / hexchar )
xchar = any ASCII CHAR between "!" (33) and "~" (126) inclusive,
except for "+" and "=".
;"hexchar"s are intended to encode octets that cannot appear
;as ASCII characters within an esmtp-value.
hexchar = ASCII "+" immediately followed by two upper case hexadecimal digits
Returns a %Status to indicate success or failure.
The send() supports the following small subset of permissible message header fields. Set the corresponding MailMessage properties before invoking send.
- Date - set from msg.Date; will be set to the current date and time if not specified
 - From - set from msg.From
 - Subject - set from msg.Subject
 - To - set from msg.To by converting to "," separated list
 - Cc - optionally set from msg.Cc by converting to "," separated list
 - Bcc - optionally set from msg.Bcc by converting to "," separated list
 - Sender - optionally set from msg.Sender
 - Reply-To - optionally set from msg.ReplyTo
 
The "MAIL FROM:" SMTP command uses the Sender field if specified, otherwise the From field.
The "RCPT TO:" SMTP command uses the To and Cc lists joined by commas.
simple e-mail address must be passed to MAIL and RCPT.
Therefore if the address is of the form name <email>,
the value passed to the SMTP command is just email.
Inherited Members
Inherited Methods
- %AddToSaveSet()
 - %ClassIsLatestVersion()
 - %ClassName()
 - %ConstructClone()
 - %DispatchClassMethod()
 - %DispatchGetModified()
 - %DispatchGetProperty()
 - %DispatchMethod()
 - %DispatchSetModified()
 - %DispatchSetMultidimProperty()
 - %DispatchSetProperty()
 - %Extends()
 - %GetParameter()
 - %IsA()
 - %IsModified()
 - %New()
 - %NormalizeObject()
 - %ObjectModified()
 - %OriginalNamespace()
 - %PackageName()
 - %RemoveFromSaveSet()
 - %SerializeObject()
 - %SetModified()
 - %ValidateObject()