-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_4_send_email_report.cs
76 lines (66 loc) · 2.69 KB
/
example_4_send_email_report.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Send FusionExport files as attachments via mail
*
* Sending email using System.Net.Mail
*
* Provide your SMTP details for setting up (line no. 44 & 45)
*
* Provide your SMTP credential (line no. 46).
*
* This sample was tested using Gmail SMTP configuration
*
* Finally, provide email metadata (details like subject, to, from) while sending email (line no. 49).
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mail;
using FusionCharts.FusionExport.Client; // Import sdk
namespace Examples
{
public static class example_4_send_email_report
{
public static void Run(string host = Constants.DEFAULT_HOST, int port = Constants.DEFAULT_PORT)
{
// Instantiate the ExportConfig class and add the required configurations
ExportConfig exportConfig = new ExportConfig();
List<string> results = new List<string>();
// Instantiate the ExportManager class
using (ExportManager exportManager = new ExportManager())
{
string chartConfigFile = System.Environment.CurrentDirectory + "\\..\\..\\resources\\multiple.json";
string templateFilePath = System.Environment.CurrentDirectory + "\\..\\..\\resources\\template.html";
exportConfig.Set("chartConfig", chartConfigFile);
exportConfig.Set("templateFilePath", templateFilePath);
exportConfig.Set("type", "pdf");
exportConfig.Set("templateFormat", "A4");
// Call the Export() method with the export config
results.AddRange(exportManager.Export(exportConfig));
}
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("<HOST>");
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("<USERNAME>", "<PASSWORD>");
SmtpServer.EnableSsl = true;
mail.From = new MailAddress("<SENDER'S EMAIL>");
mail.To.Add("<RECEIVERS'S EMAIL>");
mail.Subject = "FusionExport";
mail.Body = "Hello,\n\nKindly find the attachment of FusionExport exported files.\n\nThank you!";
System.Net.Mail.Attachment attachment;
results.ForEach(i =>
{
attachment = new System.Net.Mail.Attachment(i);
mail.Attachments.Add(attachment);
});
SmtpServer.Send(mail);
Console.WriteLine("FusionExport C# Client: Email Sent");
}
catch (Exception ex)
{
Console.WriteLine("ERROR: " + ex.Message + " " + ex.InnerException.Message);
}
}
}
}