Home > Class Reference > ENSLIB namespace > %Net.SMTP

%Net.SMTP

class %Net.SMTP extends %Library.RegisteredObject

Send a SMTP mail message

The 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 and for 8-bit locale it is the default Cache charset.

  #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 Cache' 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:\cachesys\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 (Including Private)

Method Inventory (Including Private)

Parameters

parameter Base64Seq = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/;
parameter PrintableAscii = !""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~;

Properties (Including Private)

property AllowHeaderEncoding as %Boolean [ InitialExpression = 1 ];
If true, the Send() method will encode non-ASCII header text according to the rules specified by RFC 2047. This is the default. Some mail readers do not accept the encoding specified by RFC 2047 and thus we allow disabling this encoding by setting AllowHeaderEncoding=false.
Property methods: AllowHeaderEncodingDisplayToLogical(), AllowHeaderEncodingGet(), AllowHeaderEncodingIsValid(), AllowHeaderEncodingLogicalToDisplay(), AllowHeaderEncodingNormalize(), AllowHeaderEncodingSet()
property AuthFrom as %String (MAXLEN = 255, TRUNCATE = 1);
AuthFrom specifies the address to be used for the AUTH parameter of the MAIL FROM SMTP command for SMTP authenticated session. If specified, this property will be the argument of the AUTH= extension to the MAIL FROM command. This property may be specified as "<>" to indicate that the original submitter of the messge is not known.
Property methods: AuthFromDisplayToLogical(), AuthFromGet(), AuthFromIsValid(), AuthFromLogicalToDisplay(), AuthFromLogicalToOdbc(), AuthFromNormalize(), AuthFromSet()
property ContinueAfterBadSend as %Boolean [ InitialExpression = 0 ];
If true, sending the email will continue if a send fails and failed email addresses will be added to the FailedSend list.
Property methods: ContinueAfterBadSendDisplayToLogical(), ContinueAfterBadSendGet(), ContinueAfterBadSendIsValid(), ContinueAfterBadSendLogicalToDisplay(), ContinueAfterBadSendNormalize(), ContinueAfterBadSendSet()
property Debug as %Integer [ InitialExpression = 0 ];
Property methods: DebugDisplayToLogical(), DebugGet(), DebugIsValid(), DebugLogicalToDisplay(), DebugNormalize(), DebugSet()
property Error as %String (MAXLEN = 255, TRUNCATE = 1);
If Send is called and returns an error status, the error message is in the Error property.
Property methods: ErrorDisplayToLogical(), ErrorGet(), ErrorIsValid(), ErrorLogicalToDisplay(), ErrorLogicalToOdbc(), ErrorNormalize(), ErrorSet()
property FailedSend as list of %String (MAXLEN = 8000, TRUNCATE = 1);
A list of email addresses for which the Send failed. If the Send for any address is successful, then a %Status of $$$OK is returned by Send and this list contains any failed addresses. If Send is not successful for any email address, then an %Status of $$$SMTPNoSend and all address on this list. Use (sender.FailedSend.Count()=0) to test if all sends succeeded.
Property methods: FailedSendBuildValueArray(), FailedSendCollectionToDisplay(), FailedSendCollectionToOdbc(), FailedSendDisplayToCollection(), FailedSendDisplayToLogical(), FailedSendGet(), FailedSendGetObject(), FailedSendGetObjectId(), FailedSendGetSwizzled(), FailedSendIsValid(), FailedSendLogicalToDisplay(), FailedSendLogicalToOdbc(), FailedSendNormalize(), FailedSendOdbcToCollection(), FailedSendSet(), FailedSendSetObject(), FailedSendSetObjectId()
property SSLCheckServerIdentity as %Boolean [ InitialExpression = 0 ];
When making an SSL connection check the server identity in the server certificate matches the name of the system we are connecting to. This defaults to being on and matches based on the rules layed out in section 3.1 of RFC 2818.
Property methods: SSLCheckServerIdentityDisplayToLogical(), SSLCheckServerIdentityGet(), SSLCheckServerIdentityIsValid(), SSLCheckServer