How to send email from website using gmail address?

You can make use of below mail script to send email by Gmail ID.

1. ASP.NET - C#

<!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("[email protected]");                
                       m.To.Add("[email protected]");
                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("[email protected]","******");
                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 = "[email protected]
        Dim strTo = "[email protected]"
        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("[email protected]","*******")
        SmtpMail.EnableSsl = true
        lblMessage.Text = "Mail Sent"    
    End Sub
    <form runat="server">
        <asp:Label id="lblMessage" runat="server"></asp:Label>

3. PHP

<!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 = "[email protected]";
$mail->Password = "********";
$mail->From = "[email protected]";
$mail->FromName = "demouser";
$mail->AddAddress("[email protected]","test");
$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";
  • dedicated server hosting USA, dedicated server cloud hosting, dedicated servers meaning, dedicated server hosting comparison, dedicated server gaming, dedicated server hosting cheapest, dedicated server hosting advantages, dedicated server hosting benefits, dedicated server hosting, dedicated server ark, dedicated server vs vps, dedicated server vs shared hosting, dedicated server hosting unlimited bandwidth, dedicated servers vs p2p, dedicated server minecraft, dedicated server hosting atlanta, web hosting free, vps hosting free, linux vps, web hosting for students, web hosting definition, web hosting google, web hosting vs cloud hosting, web hosting wiki, web hosting vs wordpress hosting, wordpress hosting, web hosting with free ssl
  • 457812 Users Found This Useful
Was this answer helpful?

Related Articles

How to setup phpmailer?

  Note: First you have to get PHPMailer from this link

Powered by WHMCompleteSolution