:::: MENU ::::

18 Comments

  • Reply Anup |

    Hi, Vinay.
    I was going through same sequence : but:
    VS2010, MS SQL EXPRESS 2005.,
    problem statement : 1. I have to generate monthly usage bill of club member in pdf format
    2. Send the generated bills to member ID.
    3. I have to maintain the status of bills sent/not sent /remarks etc
    .
    I goggled few things and got to know send by SMTP with attachment i can do, so i have tested basic SMTP with attachment by gmail.com ,. Now i have to go with Database…
    I code in C# and .Net : Windows Forms, plz help …. if possible i’ll share code.
    thank you
    anup.

  • Reply Andres |

    Hi, i have this error

    Msg 6528, Level 16, State 1, Procedure spSendMail, Line 3
    Assembly ‘SendEmail’ was not found in the SQL catalog of database ‘msdb’.

    • Reply Vinay Patel |

      Did you register your assembly ?
      Please make sure your DLL is available – ‘C:\SendEmail.dll’ ( i.e – this is path of example – you can have it anywhere – just make sure its available !

      Let me know if its not working.

      Thanks
      Vinay

  • Reply Nuthan |

    Hello,

    I tried exactly the same way. After all things when I try to execute I get the following error.

    Msg 6522, Level 16, State 1, Procedure spSendMail, Line 0
    A .NET Framework error occurred during execution of user-defined routine or aggregate “spSendMail”:
    System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
    System.Net.Mail.SmtpException:
    at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
    at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
    at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
    at System.Net.Mail.SmtpClient.Send(MailMessage message)
    at StoredProcedure.spSendMail(String recipients, String subject, String from, String body)
    .

    Can you please help me with this ?

    Thanks,
    Nuthan Gowda

    • Reply Vinay Patel |

      The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

      This means – you need to make sure SSL is enable in your settings using which you are sending emails – and proper SMTP port is used.

      Thanks
      Vinay

      • Reply Nuthan |

        Here is the code which I am using. I have enabled SSL and gmail port is 587.

        SmtpClient smtpClient = new SmtpClient(“smtp.gmail.com”);
        smtpClient.Credentials = new NetworkCredential(“******@gmail.com”, “****”);
        smtpClient.Port = 587;
        smtpClient.UseDefaultCredentials = false;
        smtpClient.EnableSsl = true;

        • Reply Vinay Patel |

          Can you give a try by setting up smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

          Make sure you are able to send email by logging in to account – please double check.

          Thanks
          Vinay

          • Nuthan |

            Thanks for the quick reply.

            Still I’m getting the same error. I tried to send a mail from the mail ID which I have used in the config file and it is working fine.I’m already using the same mail ID in my web application and there it works fine but through SQL Express it is giving me the above mentioned error and for your reference I have installed both SQL Server 2008 and SQL Express 2012.

            Thanks,
            Nuthan Gowda

          • Vinay Patel |

            Actually – Proc is successfully calling to your DLL – now things you need to fix is your code that sends email

            Please make sure to send test email with that function if its working or not.

            Thanks
            Vinay

  • Reply Nuthan |

    I have tested the C# code and made a following changes for it and it works fine.

    Added the Port number while creating the object

    SmtpClient smtpClient= new SmtpClient(“smtp.gmail.com”, 587);

    and deleted the following line.

    smtpClient.Port = 587;

    Thanks,
    Nuthan Gowda

  • Reply samadhan sonar |

    respected sir ,
    i have done code but when i run then this errors come,and also i change port number like 465,25,587 but also same problem .

    Msg 6522, Level 16, State 1, Procedure spSendMail, Line 0
    A .NET Framework error occurred during execution of user-defined routine or aggregate “spSendMail”:
    System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
    System.Net.Mail.SmtpException:
    at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
    at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
    at System.Net.Mail.SmtpClient.Send(MailMessage message)
    at StoredProcedures.spSendMail(String recipients, String subject, String from, String body)
    .

    • Reply Vinay Patel |

      Replace your smtp client with port attribute as below.

      SmtpClient smtpClient= new SmtpClient(“smtp.gmail.com”, 587);
      smtpClient.EnableSsl = true;

      That may help you

      Thanks
      Vinay

  • Reply Shreyas Jawalikar |

    Hello Vinay,

    I got this error

    Msg 6522, Level 16, State 1, Procedure spSendMail, Line 0
    A .NET Framework error occurred during execution of user-defined routine or aggregate “spSendMail”:
    System.Net.Mail.SmtpException: Server does not support secure connections.
    System.Net.Mail.SmtpException:
    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)
    at StoredProcedure.spSendMail(String recipients, String subject, String from, String body, String Attachments)

    I am alreay SSL is enable in my settings using and also proper SMTP port is used.
    But I am using my own smtp server

    Thanks & Ragards

    Shreyas Jawalikar

  • Reply Ray |

    The mySmtpClient.UseDefaultCredentials = false needs to come before the credentials are defined. This is creating the problem of the secure connection because it resets the credentials.

    Then it worked.

    R.

  • Reply Marco Flores |

    Hi, thanks for the tip, I modify, send the code
    using System.Net;
    using System.Net.Mail;

    public class StoreProcedure
    {
    [Microsoft.SqlServer.Server.SqlProcedure()]
    public static void spSendMail(string smtp, string usuario, string password, int port, string recipients, string subject, string from, string body)
    {
    using (MailMessage mailMessage = new MailMessage(from, recipients))
    {
    mailMessage.Subject = subject;
    mailMessage.Body = body;
    mailMessage.IsBodyHtml = true;
    using (SmtpClient smtpClient = new SmtpClient(smtp, port))
    {
    smtpClient.EnableSsl = true;
    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Credentials = new NetworkCredential(usuario, password);
    smtpClient.Send(mailMessage);
    }
    }
    }
    }

  • Reply Lili Rad |

    Hi,
    please help. I recive this error:
    Msg 6522, Level 16, State 1, Procedure spSendMail, Line 36
    A .NET Framework error occurred during execution of user-defined routine or aggregate “spSendMail”:
    System.Net.Mail.SmtpException: 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
    System.Net.Mail.SmtpException:
    at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
    at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode)
    at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception)
    at System.Net.Mail.SmtpClient.Send(MailMessage message)
    at StoredProcedure.spSendMail(String recipients, String subject, String from, String body)

    My configuration vb script is next:
    mySmtpClient = New SmtpClient(“xxserver”)

    mySmtpClient.Credentials = New NetworkCredential(“xxuser”, “xxpassw”,”xxdomain”)
    mySmtpClient.Port= 587
    mySmtpClient.UseDefaultCredentials = false
    mySmtpClient.EnableSsl=false
    mySmtpClient.Send(myMessage)

    Can you please help me with this ?
    Thanks,
    Lili

    • Reply Vinay Patel |

      The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

      This means – you need to make sure SSL is enable in your settings using which you are sending emails – and proper SMTP port is used.
      for example

      SmtpClient smtpClient = new SmtpClient(“smtp.gmail.com”,587);
      smtpClient.Credentials = new NetworkCredential(“******@gmail.com”, “****”);
      smtpClient.UseDefaultCredentials = false;
      smtpClient.EnableSsl = true;

      Thanks
      Vinay

So, what do you think ?