Question Jacopo Magliani · Nov 4, 2024

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:
ClassBO.AlertEmailSenderExtendsEns.BusinessOperation{

ParameterADAPTER = "EnsLib.EMail.OutboundAdapter";
PropertyAdapterAsEnsLib.EMail.OutboundAdapter;
ParameterINVOCATION = "Queue";
MethodOnMessage(pRequestAsMessages.AlertMsgToEmail, OutputpResponseAsMessages.AlertResponse) As%Status
{
    setsc = $$$OK
    Setmsg = ##class(%Net.MailMessage).%New()
    Setmsg.Subject=pRequest.mailObject
    setmsg.From = pRequest.sender
    Domsg.To.Insert(pRequest.destination)
    Setmsg.IsBinary=0
    Setmsg.IsHTML=0
    setsc = msg.TextData.Write(pRequest.txtMessage)
    if$$$ISERR(sc) {    
        setErrorText = "error: 'Write message stream error',"_$CHAR(10)_"details: '"_$SYSTEM.Status.DisplayError(sc)_"'"
        setErrorCode = "WRT001"
        $$$LOGINFO(ErrorText)
    }
    Setsmtp=##class(%Net.SMTP).%New()
    Setsmtp.smtpserver="smtp-mail.outlook.com"
    Setsmtp.port="587"
    //Set smtp.secure="STARTTLS"
    Setsmtp.timezone="LOCAL"
    setsmtp.SSLConfiguration = "smpt.office365.com"
    setsmtp.UseSTARTTLS = 0
    Setauth=##class(%Net.Authenticator).%New()
    Setauth.UserName=pRequest.sender
    Setauth.Password="password"
    Setsmtp.authenticator=auth
    Setsmtp.AuthFrom=pRequest.sender
    //set auth.MechanismList = "PLAIN,LOGIN"
    Setsc=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
    ifsc {
        setreport = "Email sent"
    } else {
        setreport = "Email NOT sent"
        do$System.Status.DisplayError(sc)
        $$$LOGINFO("Send Failed: "_$System.Status.DisplayError(sc))
    }
    $$$LOGINFO("STATUS SEND: "_sc)
    setpResponse = ##class(Messages.AlertResponse).%New()
    setpResponse.msgStatus = report
    setpResponse.mailStatus = 1
    quitsc
}
}

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

Comments

Jeffrey Drumm · Nov 4, 2024

I believe the host name is smtp.office365.com. You have the t and p reversed.

EDIT: For port 587, you'll also need to use STARTTLS.

0
Jacopo Magliani  Nov 4, 2024 to Jeffrey Drumm

Thank you for the response.
It appears the t and p reversed was just a typo error, in the production I had set the correct names.
If I try to set the secure property of the server to STARTTLS I obtain an error related to the property does not exist, this is why I had commented it in the code aboce

0
Jeffrey Drumm  Nov 4, 2024 to Jacopo Magliani

To use STARTTLS, you need to do the following:

  1. Create a client SSL/TLS configuration in System Administration | Security | SSL/TLS Configurations
  2. Set these properties of your smtp object:
    • Set smtp.SSLConfiguration = <name of configuration>
    • Set smtp.UseSTARTTLS = 1
0
Jacopo Magliani  Nov 7, 2024 to Jeffrey Drumm

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.

0
Enrico Parisi · Nov 7, 2024

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??

0
Jacopo Magliani  Nov 7, 2024 to Enrico Parisi

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

0
David Hockenbroch · Nov 7, 2024

Is SMTP authentication enabled in the Microsoft 365 account? That setting is turned off by default for new clients. You can check the setting in the Microsoft 365 admin portal under your active users.

0