Home / Learn programming language / How to Send email using c#

How to Send email using c#

Emailing can be something very essential to some application maybe your client might be in need of such a package.  This article describes c# send email gmail or how to send email using gmail smtp server in c#. To construct a c# smtp client, follow these:

To send an e-mail message using SmtpClient, you must specify the following information:

  • The SMTP host server that you use to send e-mail. See the Host and Port
  • Credentials for authentication, if required by the SMTP server. See the Credentials
  • The e-mail address of the sender. See the Send and SendAsync methods that take a from Also see the MailMessage. From property.
  • The e-mail address or addresses of the recipients. See the Send and SendAsync methods that take a recipient Also see the MailMessage. To property.
  • The message content. See the Send and SendAsync methods that take a body Also see the MailMessage.Body property.

Note: I used DataRow dr has a way of passing huge database record to sendMa(). So you can loop through your rows within the sendma().

  • using System;
  • usingCollections.Generic;
  • usingComponentModel;
  • usingData;
  • usingDrawing;
  • usingThreading;
  • usingConfiguration;
  • usingText;
  • usingWindows.Forms;
  • usingDiagnostics;
  • usingNet.Mail;
  • usingNet;

public void sendMa(DataRow dr)



//To, Cc, Subject, AttachmentPath, Message, ScheduledDate, Hours, as Mins;



notifyIcon1.BalloonTipText = “Sending E-Mail To: ” + dr.ItemArray[0].ToString() + “, Subject: ” + dr.ItemArray[2].ToString();



MailMessage mM = new MailMessage();

mM.From = new MailAddress(“Bambam363<bambam363photos@gmail.com>”);



if (!dr.ItemArray[1].ToString().Equals(“”))



mM.Subject = dr.ItemArray[2].ToString();



mM.Body = dr.ItemArray[4].ToString() + “<br><br>Message Sent By:<br><b>Bambam363Photos<br>09081753000<br></b>Via Email Scheduling System.”;

mM.IsBodyHtml = true;


SmtpClient client = new SmtpClient();

client.Port = 587;

client.Host = “smtp.gmail.com”;

client.EnableSsl = true;

client.Timeout = 1000000;

client.DeliveryMethod = SmtpDeliveryMethod.Network;

//client.UseDefaultCredentials = false;

client.Credentials = new System.Net.NetworkCredential(“bambam363photos@gmail.com”, “password”);




SmtpClient sC = new SmtpClient(“smtp.gmail.com”);

sC.Port = 587;

sC.Credentials = new NetworkCredential(“bambam363photos@gmail.com”, “363photos”);

sC.EnableSsl = true;




notifyIcon1.BalloonTipText = “Message Delivered successfully to ” + dr.ItemArray[0].ToString();




catch (Exception)


notifyIcon1.BalloonTipText = “Message Sending to ” + dr.ItemArray[0].ToString() + ” Failed.”;




data-matched-content-rows-num="2" data-matched-content-columns-num="2" data-matched-content-ui-type="image_stacked"

About Joseph Sam

Check Also

angularJS framework

How to crack wdms zkteco license software

WDMS is web data management server, developed by zkteco for managing their finger prints devices …

Leave a Reply

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