0
votes

The following is the error i get when i execute a simple package containing send mail task. i have configured the SMTP connection manager with server-smtp.office365.com and checked the windows authentication and ssl options too.

Thanks

Error: 0xC002F304 at Send Mail Task, Send Mail Task: An error occurred with the following error message: "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [BMXPR01CA0031.INDPRD01.PROD.OUTLOOK.COM]".

2

2 Answers

2
votes

This is a known issue. Check out this msdn link. It states the following in answer:

The SMTP Task in SSIS only supports Windows Authentication and the port number cannot be changed. For a SMTP server that uses non-Windows Authentication, we can use SmtpClient Class in Script Task to send the email

That's why sending email via office365 fails.

In order to work with office365, either you can look for third party plugins integration with SSIS or you can use script task like below:

using System.Net.Mail;
using System.Net;
.
.
.
public void Main()
{
 MailMessage mail = new MailMessage("<from email address>", "<to email address>");
 mail.Body = "ssis sample email body";
 mail.Subject = "ssis sample email subject";

 //mail.Attachments.Add(new Attachment(AttachmentDiscardContratti));
 //mail.Attachments.Add(new Attachment(AttachmentDiscardOrdini));

   SmtpClient client = new SmtpClient("smtp.office365.com", 587);
   client.EnableSsl = true;
   client.UseDefaultCredentials = false;
   client.Credentials = new NetworkCredential("<login email>", "<login password>");
   client.Send(mail);

   Dts.TaskResult = (int)ScriptResults.Success;
}

ps: swap and as I am not sure which one comes first.

another sample of code is available in this SO answer (not tested by me)

1
votes

this can easly be achieved using execute sql task. first create a stored procedure and execute sp_send_dbmail in your newly created procedure. this sp requires many parameters .. pass the values of these parameters from ssis and u will be good. please search more on google about this procedure . u can even send attachments on this procedure