ASP.NET C# Send email in background thread

System.Threading.Thread thread = new System.Threading.Thread(delegate()
{
    SMTPSend(message);
});

thread.IsBackground = true;
thread.Start();

private static void SMTPSend(MailMessage message)
{
    try
        {
            SmtpClient smtp = new SmtpClient();
            ...

On the presentation layer you do not need any AJAX or JavaScript calling code from the backend
Just plain ASP.NET button

<asp:Button ID="btnSend" runat="server" Text="Send Email" onclick="btnSend_Click" />

Code behind

protected void btnSend_Click(object sender, EventArgs e)
{
    try
    {
        Notifications.Send(email);
    }
    catch (Exception ex)
    {
        litResult.Text = ex.ToString();
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *