Send ,Mail ,,C#

Posted by Raja_89 under ASP.NET on 2/6/2013 | Points: 10 | Views : 8141 | Status : [Member] | Replies : 3
Hai Techies

How can i send a mail without username,password to gmail and to others[hotmail,in..etc] in C#.

If possible send the web application project .



Posted by: Ankitsrist on: 2/6/2013 [Member] Starter | Points: 25

hello raja,

have a look on my article in this same website, click the below link

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rimi1289 on: 2/9/2013 [Member] Starter | Points: 25

You can check the below article for what you are looking for.

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 2/17/2013 [Member] [MVP] Starter | Points: 25

Hello Raja,

Without the username and password you cannot send email as you need to authenticate your id.

You can send mails in using your gmail account to any account.

You need is the smtp host,port number,username of gmail and password for authenctication.

Use the port number for gmail as 587.

I have created a sample app please check it,it will help you.To send mails to multiple just add the emails seaprated with commas(,)

You will need 2 text box

1) Recipient textbox
2) Body Text box,this will be multiline.

I am pasting the code behind and check the HTML Mark up in the attachement.

***Code behind***
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;

public partial class SendEmail : System.Web.UI.Page
string errdesc = "0";
string fromemail, frompwd;
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)

private void SendMail()
fromemail = "";
frompwd = "yourPassword";
string ToEmail = xtxtToEmail.Text;
string Subject = xtxtSubject.Text;
string body = xtxtBody.Text;
MailMessage msg = new MailMessage(fromemail, ToEmail);
msg.Subject = Subject;
msg.IsBodyHtml = true;
msg.Body = body;
NetworkCredential ncrd = new NetworkCredential();
ncrd.UserName = fromemail;
ncrd.Password = frompwd;
SmtpClient MailClient = new SmtpClient();
MailClient.Host = "";
MailClient.Port = 587;
MailClient.UseDefaultCredentials = false;
MailClient.Credentials = ncrd;
MailClient.EnableSsl = true;
MailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
xdesc.Text = "Mail Sent Successfully";
xdesc.Visible = true;
catch (Exception ex)
errdesc = ex.Message;
xdesc.Text = errdesc;
xdesc.Visible = true;

protected void btnSend_Click(object sender, EventArgs e)

 Download source file

"Sharing is Caring"
Please mark as answer if your Query is resolved

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response