Hi everyone,
We generate a CSV file everyday at 8 am with an Automation script. I would like to send it to some collegue internally via email.
I know that it is easy to do with Reports directly in Dataminer but I wonder how I could do that with a file that is stored on the server ?
Can you help me with that ?
Please take note that the SMTP server is already configured on the server so it is ready to send emails.
Thanks a lot,
Hi Gautier,
It should be possible to send an email with an attachment via automation script. Could you try adding the code below in your automation script?
In the example below, the file is located in the DMA (C:\Skyline DataMiner\Documents\Reports\CPUReport.csv)
string CSVPath = @"C:\Skyline DataMiner\Documents\Reports\CPUReport.csv"; EmailAttachment myAttachement = new EmailAttachment("CPUReport.csv", File.ReadAllBytes(CSVPath)); SendEmailMessage myMessage = new SendEmailMessage() { Attachments = new EmailAttachment[1] { myAttachement }, From = "Reports@DataMiner.be", To = "your.email@skyline.be", Subject = "CPU Report", Body = "Find attached the CPU CSV Report" }; engine.SendSLNetMessage(myMessage);
Hi Gautier,
As Daniela mentioned, you need to include the following namespace:
using Skyline.DataMiner.Net.Messages;
Please find below a full example:
++++++++++++++++++++++
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using Skyline.DataMiner.Automation;
using Skyline.DataMiner.Net.Messages;
class Script
{
public void Run(Engine engine)
{
string CSVPath = @”C:Skyline DataMinerDocumentsDMA_COMMON_DOCUMENTSTEST_REPORTStestReport.csv”;
EmailAttachment myAttachement = new EmailAttachment(“CPUReport.csv”, File.ReadAllBytes(CSVPath));
SendEmailMessage myMessage = new SendEmailMessage()
{
Attachments = new EmailAttachment[1] { myAttachement },
From = “Reports@DataMiner.be”,
To = “your.email@skyline.be”,
Subject = “CPU Report”,
Body = “Find attached the test report”
};
engine.SendSLNetMessage(myMessage);
}
}
++++++++++++++++++++++++++++++++
Disclaimer about Skyline.DataMiner.Net.Messages:
Note that this is an internal call and we do not recommend using this, as it is not officially supported and we cannot guarantee that it will still work in the future. As a rule, you should avoid using SLNet calls, as these are subject to change without notice. We recommend to instead always use the correct UI or automation options provided in DataMiner Automation or through our web API.
Dont forget to add the using "Skyline.DataMiner.Net.Messages;"
Hi all,
We're trying this solution but when executing it returns:
"Script 'Automation script' failed:
The following was returned from the script:
(Code: 0x800402D5) Skyline.DataMiner.Net.Exceptions.DataMinerCOMException: Failed to send e-mail.
---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800402D5"
Do you have any idea what could be wrong? Kind Regards,
Hi Rosalia,
Sorry for the late response. There is already a similar question:
https://community.dataminer.services/question/issue-sending-email-from-dm-v9-6/?hilite=800402D5
Can you verify if the DMA has been configured correctly to send emails? The configuration is in the C:Skyline DataMinerDataMiner.xml configuration file?
Thanks a lot Miguel !
I gave it a try but I have some errors. Do I need to include some dlls ?
Thanks