Sample Code About Sending Emails Via Gmail


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<%@import namespace="System.Net"%>
<%@import namespace="System.Net.Mail"%>
<script language="C#" runat="server">
protected void Page_Load(object sender, EventArgs e)
MailMessage m = new MailMessage();
SmtpClient sc = new SmtpClient();
m.From = new MailAddress("");
m.Subject = "This is a Test Mail";
m.IsBodyHtml = true;
m.Body = "test gmail";
sc.Host = "";
sc.Port = 587;
sc.Credentials = new System.Net.NetworkCredential("","******");

sc.EnableSsl = true;
Response.Write("Email Send successfully");
catch (Exception ex)
<form runat="server">
<asp:Label id="lblMessage" runat="server"></asp:Label>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<%@ Page Language="VB" %>

<%@ Import Namespace="System.Net.Mail" %>

<script runat="server">

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


        Dim strFrom = "" 

        Dim strTo = ""

        Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo))

        MailMsg.BodyEncoding = Encoding.Default

        MailMsg.Subject = "This is a test"

        MailMsg.Body = "This is a sample message using SMTP authentication"

        MailMsg.Priority = MailPriority.High

        MailMsg.IsBodyHtml = True


        Dim SmtpMail As New SmtpClient

        Dim basicAuthenticationInfo

        SmtpMail.Host = ""


        SmtpMail.DeliveryMethod = SmtpDeliveryMethod.Network

        SmtpMail.UseDefaultCredentials = False

        SmtpMail.Credentials = new System.Net.NetworkCredential("","*******")

        SmtpMail.EnableSsl = true


        lblMessage.Text = "Mail Sent"    

    End Sub




    <form runat="server">

        <asp:Label id="lblMessage" runat="server"></asp:Label>






<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">




include("class.phpmailer.php"); //you have to upload class files "class.phpmailer.php" and "class.smtp.php"

$mail new PHPMailer();


$mail->SMTPAuth = true;

$mail->SMTPSecure = "tls";

$mail->Host = "";

$mail->Port = 587;

$mail->Username = "";

$mail->Password = "********";

$mail->From = "";

$mail->FromName = "demouser";


$mail->Subject = "This is the subject";

$mail->Body = "This is the body";

$mail->WordWrap = 50;


if(!$mail->Send()) {

echo "Mailer Error: " . $mail->ErrorInfo;

} else {

echo "Message has been sent";







  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

SQL server- network related or instance-specific error happened while connection establishing

  Instance-specific or network related error happening while connecting to SQL server   Please...

OleDB connection string examples

OleDB connection string examples MS Access (Jet) "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA...

Do you allow custom COM components?

Do you allow custom COM components? We are not offering to install the custom COM components...

Error when accessing a WCF services

Error when accessing a WCF services Error when accessing a WCF service: "IIS specified...

How to cache static contents to client with UseMaxAge?

You can consider to caches static contents to the client with UseMaxAge if your website has too...