How to send Email via SmtpClient using XProtects Email configuration

Hi all!

In our Desk Client plugin, we would like to send an email via the configured SMTP server using .net SmtpClient. Therefore we retrieve the required data through ToolOptionMailServer :

var mailNotificationProfiles = ms.MailNotificationProfileFolder.MailNotificationProfiles;
            
            var mailServerSettingsConfigItem = ms.ToolOptionFolder.ToolOptions.FirstOrDefault(x => x.DisplayName.Equals("Mail server settings"));
 
            var mailServerSettings = mailServerSettingsConfigItem as ToolOptionMailServer;

The password that is returned seems like to be in Hash-form. When trying to send an Email via SmtpClient.Send():

SmtpClient smtp = new SmtpClient( smtpHost, smtpPort )
         {
            Credentials = new NetworkCredential( username, password ),
            EnableSsl = useSsl,
         };
 
         // Send the email
         try
         {
            smtp.Send( mail );
         }
         catch( Exception ex )
         { }

we catch an “Invalid Authentication” exception. Is there a way to achieve proper authentication using the provided information by ToolOptionMailServer?

The Email configuration in XProtect was tested to be correct and working, by the way.

Can you please provide information on how the password that is provided by ToolOptionMailServer

is encoded or encrypted?

Unfortunately, our investigation into this have revealed that the password is encrypted, and there is no method to get it in a decrypted state instead.

A possible workaround is to setup

  • a user-defined event
  • a notification profile
  • a rule that sends a notification on a user-defined event

The idea is that you client raises the user-defined event instead of sending the email itself.

Of course this is not nearly as flexible as just being able to send an email knowing the mail server setup to use.

Might it work as a workaround?

Thx Bo!

We will have to re-evaluate our solution with this information in mind!