从终端控制台手动发送邮件?

Manually send mail from terminal console?

我们有一个 class 可以构建和发送邮件消息。我想进行一些更改,但在此之前我想测试一些内容(例如 URL 的显示方式)。我正在尝试从控制台手动发送消息,但出现了一些错误。这是 class 的 SendMessage 方法:

Method SendMessage(pSubject As %String, pMessage As %String, pEmailAddresses) As %Status
{
    set tSC=$$$OK
    set tMailMessage=##class(%Net.MailMessage).%New()
    do tMailMessage.To.Insert($PIECE(pEmailAddresses,",",1))
    for tI=2:1:$LENGTH(pEmailAddresses,",") {
        do tMailMessage.Cc.Insert($PIECE(pEmailAddresses,",",tI))
    }

    set tMailMessage.Subject=pSubject
    set tMailMessage.Charset="iso-8859-1"
    set tSC=tMailMessage.TextData.Write(pMessage)
    quit:'tSC
    Set tSC1=..Adapter.SendMail(tMailMessage)
    if 'tSC1 {
        //Log warning about being unable to send mail.
        do $SYSTEM.Status.DecomposeStatus(tSC1,.err)
        $$$LOGWARNING("Could not send email: "_err(err))
        kill err
    }

    quit tSC
}

我可以从终端实例化 MailMessage class 并设置正文数据,但是当我尝试发送时出现错误:

USER>set tMailMessage=##class(%Net.MailMessage).%New()

USER>do tMailMessage.To.Insert("me@email.com")

USER>set tSC=tMailMessage.TextData.Write("This is a URL test http://www.google.com, thank you")

USER>set tMailMessage.Subject="This is a test"

USER>set tMailMessage.Charset="iso-8859-1"

USER>set tSC1=..Adapter.SendMail(tMailMessage)

SET tSC1=..Adapter.SendMail(tMailMessage)
^
<NO CURRENT OBJECT>

如您所见,当我尝试 SendMail 时,它告诉我 NO CURRENT OBJECT

更新 我注意到 class:

顶部的这些行
Parameter ADAPTER = "EnsLib.EMail.OutboundAdapter";

Property Adapter As EnsLib.EMail.OutboundAdapter;

所以我尝试了 USER>set tSC1=EnsLib.EMail.OutboundAdapter.SendMail(tMailMessage) 但结果是 <UNDEFINED> *EnsLib

因为我认为你在处理 Ensemble Service。但是为了测试,你不应该使用那个类。要发送电子邮件,您可以直接使用 %Net.SMTP。 所以,而不是 ..Adapter.SendMail 使用此代码

set s=##class(%Net.SMTP).%New()
set s.smtpserver="SMTP server name"

#; if SMTP server needs auth
set auth=##class(%Net.Authenticator).%New() ; use default authentication list
set auth.UserName="myUser"
set auth.Password="myPassword"
set s.authenticator=auth

set status=s.Send(tMailMessage)
if $$$ISERR(status) do $system.OBJ.DisplayError(status)