GOAL: send an html email using Sql Server Integration Service
PROBLEM: the Send Mail Task in SSIS allows only email in text format and not in html format.
SOLUTION: use a C# script instead the Send Mail Task to create and send the email.
1) Add a Script Task to the solution and choose C# as language
2) Open the task and click on Edit Script
3) Under the "region namespaces" part, add this namespace:
using System.Net.Mail;
4) After the "// TODO: Add your code here" add the following code (replace the highlighted part with your parameters):
// Create email
MailMessage msg = new MailMessage();
// From
msg.From = new MailAddress("example@gmail.com");
string user = "massimiliano.figini";
string password = "***************";
// To
msg.To.Add("example@yahoo.com");
// CC
msg.To.Add("example2@yahoo.it");
// Subject
msg.Subject = "Email subject test";
// Text in html
msg.Body = "<html><body><h1>Test</h1><p>Test <b>test</b> message.</p></body></html>";
msg.IsBodyHtml = true;
// Attachment
msg.Attachments.Add(new Attachment("C:\\Test.txt"));
// Send email
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(user, password);
smtp.EnableSsl = true;
smtp.Send(msg);
Categories
Bash
(3)
BOT
(2)
C#
(1)
Cluster Analysis
(1)
Data Cleaning
(6)
Data Ingestion
(2)
Data Science Specialization
(10)
Data Visualization
(15)
ggplot2
(1)
Hadoop
(1)
Hashnode
(3)
Machine Learning
(5)
MapReduce
(1)
Maps
(1)
Markdown
(7)
Market Basket Analysis
(1)
MATLAB
(1)
Matplotlib
(3)
Numpy
(2)
Octave
(1)
Pandas
(3)
Python
(17)
R
(22)
Regression
(7)
scikit-learn
(1)
Seaborn
(1)
Shell
(3)
Shiny App
(1)
SSIS
(3)
Statistical Inference
(2)
T-SQL
(8)
Unix
(3)
No comments:
Post a Comment