Monday, 6 August 2012

How to send bulk email from asp.net page

How to send bulk email from asp.net page 


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SENDINGEMAIL.aspx.cs" Inherits="SENDINGEMAIL" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .style1
        {
            width: 100%;
            height: 485px;
        }
    
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
    </div>
    <p>
        &nbsp;</p>
    <table class="style1">
        <tr>
            <td class="style2">
                To:-</td>
            <td>
                <asp:TextBox ID="txtsentmailid" runat="server" Height="22px" Width="838px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style2">
                Subject:-</td>
            <td>
                <asp:TextBox ID="txtsubject" runat="server" Height="16px" Width="840px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style2" colspan="2">
                <asp:TextBox ID="txtbodymail" runat="server" Height="439px"
                    TextMode="MultiLine" Width="906px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style2" colspan="2">
                <asp:Button ID="btnsendmail" runat="server"
                    Text="Send Mail" onclick="btnsendmail_Click" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>



//C# code


First add reffrence like this:- using System.Net.Mail;

Now Write this code click event of btnsendmail button
   
    protected void btnsendmail_Click(object sender, EventArgs e)
    {
        MailMessage ml = new MailMessage();
        ml.To.Add(txtsentmailid.Text);

        ml.From = new MailAddress("yourgmail  id");
        ml.Subject = txtsubject.Text;

        string Bd = txtbodymail.Text;
        ml.Body = Bd;

        ml.IsBodyHtml = true;

        SmtpClient smtpcode = new SmtpClient();
        smtpcode.Host = "smtp.gmail.com";
        smtpcode.Port = 587;
        smtpcode.UseDefaultCredentials = false;
        smtpcode.Credentials = new System.Net.NetworkCredential
        ("your gmail id ", "your gmail password");
        smtpcode.EnableSsl = true;
        smtpcode.Send(ml);
    }

0 comments: