Click here to Skip to main content
13,293,369 members (49,894 online)
Rate this:
Please Sign up or sign in to vote.
See more:
following is the Code I am using to Send Email
through ASP.NET and C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Configuration;
public partial class _Default : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e)
    protected void bt_sendMail_Click(object sender, EventArgs e)
        SendMail(tb_GmailAccount.Text, tb_GmailPassword.Text, tb_RecieverEmail.Text, tb_Subject.Text, tb_Message.Text);
    public  void SendMail(string gMailAccount, string password, string to, string subject, string message)
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(gMailAccount);
            msg.To.Add(new MailAddress(to));
            msg.Subject = subject;
            msg.Body = message;
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.Normal;
            var client = new SmtpClient("", 587)
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(gMailAccount, password),
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network
        catch (Exception ex)
            string s = ex.Message; ;

But getting Exception as SMTP EXCEPTION CAUGHT ..Failure to send.
Please Guide me where is the Problem
Posted 17-Nov-12 1:50am
Dhinesh kumar.V 17-Nov-12 6:52am
Use this one.. Hope this one is help you.

SmtpClient Client;
MailMessage Msg;
Attachment Anexo;

use this try block coding under button_click event
Client = new SmtpClient("");
Msg = new MailMessage();
Anexo = new System.Net.Mail.Attachment(label7.Text);
Msg.From = new MailAddress(textBox1.Text);
Msg.Body = richTextBox1.Text;
Msg.Subject = textBox3.Text;
SmtpClient smtps = new SmtpClient("", 587);
Client.Credentials = new NetworkCredential();
Client.Port = 587;
Client.Credentials = new System.Net.NetworkCredential(textBox1.Text, textBox2.Text);
Client.EnableSsl = true;
// MessageBox.Show("adf");
Karwa_Vivek 17-Nov-12 7:05am
No its Not working
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

refer this

Failure sending mail[^]

Hope This Helps..
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

using System.Net;
using System.Net.Mail;
public string ord, body;
MailMessage oMail = new MailMessage();
SmtpClient oSmtp = new SmtpClient("", 587);
            oMail.From = new MailAddress("");
            oMail.Subject = "Subject";
            body = "Hello, <br />";
            body += "How are you";
            oMail.Body = body;
            oMail.IsBodyHtml = true;
            oSmtp.UseDefaultCredentials = false;
            oSmtp.Credentials = new System.Net.NetworkCredential("", "password");
            oSmtp.EnableSsl = true;
        catch { }

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171207.1 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100