Public Member Functions | |
_.Library.String | EncodeXtext (_.Library.String text) |
xtext encoding is defined in RFC 1891 as: More... | |
Login (_.Library.Boolean authenticated) | |
Setup session with the SMTP server. More... | |
_.Library.Status | Send (_.Net.MailMessage msg) |
Used to send msg to SMTP server. More... | |
_.Library.String | zone () |
Return timezone converted to RFC822 format. | |
![]() | |
_.Library.Status | OnAddToSaveSet (_.Library.Integer depth, _.Library.Integer insert, _.Library.Integer callcount) |
This callback method is invoked when the current object is added to the SaveSet,. More... | |
_.Library.Status | OnClose () |
This callback method is invoked by the <METHOD>Close</METHOD> method to. More... | |
_.Library.Status | OnConstructClone (_.Library.RegisteredObject object, _.Library.Boolean deep, _.Library.String cloned) |
This callback method is invoked by the <METHOD>ConstructClone</METHOD> method to. More... | |
_.Library.Status | OnNew () |
This callback method is invoked by the <METHOD>New</METHOD> method to. More... | |
_.Library.Status | OnValidateObject () |
This callback method is invoked by the <METHOD>ValidateObject</METHOD> method to. More... | |
Public Attributes | |
AllowHeaderEncoding | |
If true, the <method>Send</method> method will encode non-ASCII header. More... | |
AuthFrom | |
<property>AuthFrom</property> specifies the address to be used for the More... | |
ContinueAfterBadSend | |
If true, sending the email will continue if a send fails and failed email. More... | |
Debug | |
More... | |
Error | |
If Send is called and returns an error status, the error. More... | |
FailedSend | |
A list of email addresses for which the Send failed. More... | |
IPVersion | |
<property>IPVersion</property> specifies the versin of IP address to be used More... | |
IgnoreFailedAuth | |
If false (as is the default), Send() will fail if there is an authenticator present but authentication with the server fails. More... | |
SSLCheckServerIdentity | |
When making an SSL connection check the server identity in the server certificate matches the name of the system we are connecting to. More... | |
SSLConfiguration | |
The name of the activated TLS/SSL configuration to use for smpts requests. More... | |
ShowBcc | |
If ShowBcc = true (1), then Bcc headers will be written to the email message. More... | |
UseSTARTTLS | |
If true then the STARTTLS extension to SMTP (RFC 3207) should be used to authenticate. More... | |
authenticator | |
To do SMTP authentication with the SMTP server (as defined by RFC 2554),. More... | |
bufcount | |
More... | |
localhost | |
The sending host, default is $ZU(110). More... | |
port | |
The port of the SMTP server, the default is 25 for plain text and 465 for SSL. More... | |
smtpserver | |
the name of the SMTP server More... | |
timezone | |
timezone as specified by RFC822, for example "EST", "PDT", "-0400". More... | |
Private Member Functions | |
_.Library.String | __zzErrorTrap () |
Error trap. | |
Additional Inherited Members | |
![]() | |
CAPTION = None | |
Optional name used by the Form Wizard for a class when generating forms. More... | |
JAVATYPE = None | |
The Java type to be used when exported. | |
PROPERTYVALIDATION = None | |
This parameter controls the default validation behavior for the object. More... | |
For information on using this class, see Sending and Receiving Email.
Send a SMTP mail message
The <property>Charset</property> property of each <class>Net.MailMessagePart</class> determines the charset for text MIME parts. The charset property is ignored unless <property>ContentType</property>=text/... <property>Charset</property> 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 <class>Net.MailMessagePart</class>. 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
_.Library.String EncodeXtext | ( | _.Library.String | text | ) |
xtext encoding is defined in RFC 1891 as:
"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
Login | ( | _.Library.Boolean | authenticated | ) |
_.Library.Status Send | ( | _.Net.MailMessage | msg | ) |
Used to send msg to SMTP server.
Returns a Status to indicate success or failure.
The <method>send</method> supports the following small subset of permissible message header fields. Set the corresponding MailMessage properties before invoking send.
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.
AllowHeaderEncoding |
If true, the <method>Send</method> 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.
AuthFrom |
<property>AuthFrom</property> 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.
ContinueAfterBadSend |
If true, sending the email will continue if a send fails and failed email.
addresses will be added to the FailedSend list.
Debug |
Error |
If Send is called and returns an error status, the error.
message is in the Error property.
FailedSend |
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.
IPVersion |
<property>IPVersion</property> specifies the versin of IP address to be used
to connect SMTP server. The valid values are:
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.
IgnoreFailedAuth |
If false (as is the default), Send() will fail if there is an authenticator present but authentication with the server fails.
If true, Send() will ignore a failure to authenticate and proceed with sending without authentication. If no authenticator is present, authentication is never attempted and so this property is ignored.
SSLCheckServerIdentity |
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.
SSLConfiguration |
The name of the activated TLS/SSL configuration to use for smpts requests.
ShowBcc |
If ShowBcc = true (1), then Bcc headers will be written to the email message.
The Bcc headers will usually be filtered out by the SMTP server.
UseSTARTTLS |
authenticator |
To do SMTP authentication with the SMTP server (as defined by RFC 2554),.
instantiate a <class>Net.Authenticator</class> object, set UserName and Password properties of the authenticator and assign it to this property. An example of the use of authenticator follows.
#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
bufcount |
localhost |
The sending host, default is $ZU(110).
port |
The port of the SMTP server, the default is 25 for plain text and 465 for SSL.
smtpserver |
the name of the SMTP server
timezone |
timezone as specified by RFC822, for example "EST", "PDT", "-0400".
If timezone is "LOCAL", then the local timezone expressed as "+nnnn" or "-nnnn" is used. If timezone is not set, then "UT" is used for the timezone and universal time is used in the message.