Question
· Nov 4

Operation Email sender error #6034 connection with SMTP not successfull

I am developing a business operation that receives a request, creates a message with the data contained in it and sends it to an outlook email. For testing purposes both the sender and the destination are the same email account
This is the code:
Class BO.AlertEmailSender Extends Ens.BusinessOperation{

Parameter ADAPTER = "EnsLib.EMail.OutboundAdapter";
Property Adapter As EnsLib.EMail.OutboundAdapter;
Parameter INVOCATION = "Queue";
Method OnMessage(pRequest As Messages.AlertMsgToEmail, Output pResponse As Messages.AlertResponse) As %Status
{
    set sc = $$$OK
    Set msg = ##class(%Net.MailMessage).%New()
    Set msg.Subject=pRequest.mailObject
    set msg.From = pRequest.sender
    Do msg.To.Insert(pRequest.destination)
    Set msg.IsBinary=0
    Set msg.IsHTML=0
    set sc = msg.TextData.Write(pRequest.txtMessage)
    if $$$ISERR(sc) {    
        set ErrorText = "error: 'Write message stream error',"_$CHAR(10)_"details: '"_$SYSTEM.Status.DisplayError(sc)_"'"
        set ErrorCode = "WRT001"
        $$$LOGINFO(ErrorText)
    }
    Set smtp=##class(%Net.SMTP).%New()
    Set smtp.smtpserver="smtp-mail.outlook.com"
    Set smtp.port="587"
    //Set smtp.secure="STARTTLS"
    Set smtp.timezone="LOCAL"
    set smtp.SSLConfiguration = "smpt.office365.com"
    set smtp.UseSTARTTLS = 0
    Set auth=##class(%Net.Authenticator).%New()
    Set auth.UserName=pRequest.sender
    Set auth.Password="password"
    Set smtp.authenticator=auth
    Set smtp.AuthFrom=pRequest.sender
    //set auth.MechanismList = "PLAIN,LOGIN"
    Set sc=smtp.Send(msg)
    If $$$ISERR(sc) {
    Do $System.Status.DisplayError(sc)
    $$$LOGINFO(smtp.Error)
    Quit ""
  }
    // send email  
    //set sc = ..Adapter.SendMail(msg)
    // check for errors
    if sc {
        set report = "Email sent"
    } else {
        set report = "Email NOT sent"
        do $System.Status.DisplayError(sc)
        $$$LOGINFO("Send Failed: "_$System.Status.DisplayError(sc))
    }
    $$$LOGINFO("STATUS SEND: "_sc)
    set pResponse = ##class(Messages.AlertResponse).%New()
    set pResponse.msgStatus = report
    set pResponse.mailStatus = 1
    quit sc
}
}

In the InterSystems production portal I have set the operation, activated it and configured the base settings and connection settings as this
Server SMTP = smpt.office365.com
Port SMTP = 587
Credentials = credentials
Config SSL = smpt.office365

In the past I had obtained these errors: (translated from Italian)
-when I had wrongly defined smtpserver="smpt.office365.com" I obtained error #6031 "impossible to open connection TCP/IP"
- when SSLConfiguration was not present I obtained error #6034 "connection with server SMTP not successfull during command MAIL FROM:<READ>zSend+122^%Net.SMTP.1"
I do not receive anymore these errors after the corrections present in the code above, but I obtain error #6034
Connection with SMTP server not successfull during command init: <READ>zGetResponse+5^%Net.SMTP.1.
How do I proceed?

Product version: IRIS 2021.1
Discussion (7)4
Log in or sign up to continue

The configuration was already present in the production, but still I get the error that the property UseSTARTTLS is not available.
I have switched to use gmail for the sender instead of Outlook following this guide
Configuring email alerts with Gmail on IRIS management portal |
and it works just fine, but I wonder what is the problem with the configuration settings to use Outlook.

Your Business Operation (is supposed to) use the EnsLib.EMail.OutboundAdapter, but the in the code you use the %Net.SMTP class directly, ignoring the adapter.

In the Interoperability portal your implementation  provide the email adapter configuration (server, certificate, credentials etc. etc.) that in fact are then ignored in the code. This makes it very confusing for anyone using the portal, now...and in the future!

So the first question is, do you want to use the EnsLib.EMail.OutboundAdapter or not?

If you want to use the adapter, if you have not already done it, I suggest to start with the documentation:

Using the Email Outbound Adapter and Settings for the Email Outbound Adapter

If you don't what to use the EnsLib.EMail.OutboundAdapter, then remove the reference from your code.

Using %Net.SMTP class directly (right?), you said that "...I get the error that the property UseSTARTTLS is not available." and this is very strange, can you confirm you are using IRIS version 2021.1?
Is your code the same as in your first post or has changed? If changed, can you post the modified code that fail?

Last but not least, are you sure your outlook.com account allow user/password authentication? Or you must use OAuth2 authentication??

Thank you for the detailed response.

You are right about the outbound adapter but in reality the code I have provided was a test code I have developed because the adapter did not work.

Very probably both the adapter and the %Net.SMTP class do not work in my case because of configuration problems with outlook, since I have obtained successfull results using gmail instead. 
Regarding the user/password or OAuth2, I was provided with code of old projects that used the same configuration and it worked just fine, while now that I am working with a new project it does not anymore.

I am sure the version of IRIS is 2021.1, I have just checked in the portal.

I will try different settings based on your response