1. ASP.NET - C#
<%@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();
try
{
m.Subject = "This is a Test Mail";
m.IsBodyHtml = true;
m.Body = "test gmail";
sc.Host = "smtp.gmail.com";
sc.Port = 587;
sc.EnableSsl = true;
sc.Send(m);
Response.Write("Email Send successfully");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
</script>
<html>
<body>
<form runat="server">
<asp:Label id="lblMessage" runat="server"></asp:Label>
</form>
</body>
</html>
2. ASP.NET - VB.NET
<%@ 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 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 = "smtp.gmail.com"
SmtpMail.Port=587
SmtpMail.DeliveryMethod = SmtpDeliveryMethod.Network
SmtpMail.UseDefaultCredentials = False
SmtpMail.Credentials = new System.Net.NetworkCredential("[email protected]","*******")
SmtpMail.EnableSsl = true
SmtpMail.Send(MailMsg)
lblMessage.Text = "Mail Sent"
End Sub
</script>
<html>
<body>
<form runat="server">
<asp:Label id="lblMessage" runat="server"></asp:Label>
</form>
</body>
</html>
3. PHP
<html>
<body>
<?php
include("class.phpmailer.php"); //you have to upload class files "class.phpmailer.php" and "class.smtp.php"
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Password = "********";
$mail->FromName = "demouser";
$mail->Subject = "This is the subject";
$mail->Body = "This is the body";
$mail->WordWrap = 50;
$mail->IsHTML(true);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
</body>
</html>