August 5, 2021 at 4:12 pm
Can anyone help me with some script to send email with C#. I tried the "Send Mail Task" and it failed also. Here's what I have so far. It runs but I get no mail. My port number is 25 and I'm using basic authentication with password. Any ideas?:
public void Main()
{
try
{
MailMessage mailMsg = new MailMessage();
mailMsg.To.Add(new MailAddress("bcamp@square.com", "Support"));
mailMsg.From = new MailAddress("matrix2@square.com", "ETL Process");
mailMsg.Subject = "SUCCESS:ADP Users File Loaded";
string text = string.Concat("The ETL Process successfully loaded all the File data table.");
SmtpClient smtpClient = new SmtpClient("mail050-1.exch050.serverdata.net", Convert.ToInt32(25));
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("anomaly", "H78d165265");
smtpClient.Credentials = credentials;
smtpClient.Send(mailMsg);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
August 5, 2021 at 5:59 pm
This worked!:
using System.Net;
public void Main()
{
try
{
MailMessage mailMsg = new MailMessage();
mailMsg.To.Add(new MailAddress("bcamp@square.com", "Support"));
mailMsg.From = new MailAddress("matrix2@square.com", "ETL Process");
mailMsg.Subject = "SUCCESS:ADP Users File Loaded";
string text = string.Concat("The ETL Process successfully loaded all the ADP Users File data table.");
SmtpClient smtpClient = new SmtpClient("mail030-1.exch050.server.net");
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("matrix2@square.com", "H78dd424nssw265");
smtpClient.Credentials = credentials;
smtpClient.Port = 25;
smtpClient.EnableSsl = true;
smtpClient.Send(mailMsg);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
June 6, 2023 at 7:15 am
Check this one....send email from c#
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply