0

I am trying to send an email from a SSIS package to a SharePoint 2013 Document library. I am using a Script Task for this. The code I am using is as follows.

public void Main()
{
    String Sender = "first.last@something.this.com";
    String Recipient = "newtest@test.something.this.com";
    String SMTPServer = "mail.test.something.this.com";         
    String MailSubject = "User Details - Updated Records";
    String MailBody = "Please find the file attached herewith.";

    try
    {
        // Create an email and change the format to HTML
        MailMessage MailMessage = new MailMessage(Sender, Recipient, MailSubject, MailBody);
        MailMessage.IsBodyHtml = true;
        Attachment AttachmentLocation = new Attachment("C:\\RootFolder\\SubFolder1\\SubFolder2\\NewData.csv");

        // Create a SMTP client to send the email
        SmtpClient mySmtpClient = new SmtpClient(SMTPServer);
        //System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("test\\first.last", "**********");
        mySmtpClient.UseDefaultCredentials = true;
        mySmtpClient.EnableSsl = true;
        //mySmtpClient.Credentials = credentials;
        MailMessage.Attachments.Add(AttachmentLocation);
        mySmtpClient.Send(MailMessage);

        Dts.TaskResult = (int)ScriptResults.Success;
    }
    catch (Exception ex)
    {
        //An error occurred.
        MessageBox.Show("Error : " + ex.Message + "\r" + ex.StackTrace);

        Dts.Events.FireError(0, "Script Task Example", ex.Message + "\r" + ex.StackTrace, String.Empty, 0);
        Dts.TaskResult = (int)ScriptResults.Failure;
    }
}

But i am getting following error at mySmtpClient.Send(MailMessage);

Exception

Unable to connect to the remote server

at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message)

Inner Exception

No connection could be made because the target machine actively refused it xxx.xxx.xxx.xxx:25

at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)

Mentions :

  1. I would like to mention that the SQL Server running my SSIS package is on Domain 1 and the SharePoint Farm is on Domain 2.

  2. I have checked the Drop folder also. But, the mail is not there.

  3. I am able to send the same mail manually from my Outlook to the same Document Library.

  • 2
    The error message says unable to connect to the Email Server. Check mail server is accessible from the SSIS box. Check Firewall is not blocking etc. – Amal Hashim Dec 8 '14 at 20:24
0

It was the silly one. The SMTP server i was using turned out to be wrong. Getting confused between many different environments i picked up the wrong SMTP server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.