SIGN UP MEMBER LOGIN:    
ARTICLE

Best technique of sending bulk email.

Posted by sangeeta mishra Articles | Learn .NET September 10, 2009
Tags: bulk email
This article describe how to send bulk email
Reader Level:

This article basically describe how to send bulk mail to multiple recepctionist.for this we use-
System.Net.Mail namespace.

System.Net.Mail is the namespace used to send email if you are using the 2.0 (or higher) .NET Framework.
Although some functionality has been removed, the new System.Net.Mail namespace is much more versatile than the older CDO dependant System.Web.Mail.


For modern business, bulk email -also known as spam mail- has become one of the more successful ways to market and advertise a company's products and services. But like any marketing strategy, bulk emailing has its share of advantages and disadvantages.
One of the downsides to bulk email is that it may not reach its target recipient. This can be blamed on bulk email blockers programmed into email accounts. Blockers segregate bulk email into a separate email folder, so the reader cannot directly access it from his inbox.
On the other hand, one of the advantages of bulk emailing is that it has the power to communicate directly to the target market. Such communication is done individually, so much so that the recipient may be able to identify personally with the message. Another benefit for businesses using this strategy is that they do not have to spend so much on advertising. Using bulk email is actually much cheaper than utilizing print advertisements or radio and television commercials.

What do I need to send email in .NET

First, and foremost, you need the .NET Framework installed. Then you need a reference to the System.dll (automatically included in ASP.NET applications). Then you need to use the System.Net.Mail namespace to create and send email messages.
Once you have programmatically set up your application, you will need a relay server to send email through. A relay server is a mail server, or a SMTP server/service, that can handle sending email. System.Net.Mail simply sends the mail to a relay server, and the relay server is responsible for delivering it to the final destination.

.aspx page:-


<
body>
<form id="form1" runat="server">
<div>
<table align="center" bgcolor="#cccc99">
<tr>
<td>
<table cellpadding=3 cellspacing=4 bgcolor="#ccffcc">
<tr>
<td>
<asp:Label ID="lblto" runat="server" Text="To"></asp:Label>
&nbsp;
<asp:TextBox ID="txtemailto" runat="server" Width="250"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblfrom" runat="server" Text="From"></asp:Label>
&nbsp;
<asp:TextBox ID="txtemailfrom" runat="server" Width="250"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblBcc" runat="server" Text="Bcc"></asp:Label>
&nbsp;
<asp:TextBox ID="txtBcc" runat="server" Width="250"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblcc" runat="server" Text="cc"></asp:Label>
&nbsp;
<asp:TextBox ID="txtcc" runat="server" Width="250"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblsubject" runat="server" Text="Subject"></asp:Label>
&nbsp;
<asp:TextBox ID="txtsubject" runat="server" Width="250"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblbody" runat="server" Text="Body"></asp:Label>
&nbsp;
<asp:TextBox ID="txtbody" runat="server" Width="250" Height="50"></asp:TextBox>
</td>

</tr>
<tr>
<td>
<asp:Label ID="lblAttachFile" runat="server" Text="File to send:" Width="100px"></asp:Label>
<input type="file" id="fileAttachement" runat="server" name="fileAttachement" width="200px" />
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="btn1" runat="server" Text="Send" OnClick="btn1_Click"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</
body>

.cs page:-

using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Net.Mail;
using
System.Data.SqlClient;
public
partial class bulkmail : System.Web.UI.Page
{
SqlDataAdapter da;
DataSet ds = new DataSet();
SqlConnection con;
SqlCommand cmd = new SqlCommand();
SqlDataReader read_Email;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn1_Click(object sender, EventArgs e)
{
ArrayList list_emails = new ArrayList();
int i = 0;
string email;
con=
new SqlConnection(ConfigurationManager.AppSettings["connect"]);
con.Open();
SqlCommand cmd = new SqlCommand("Select email from Email", con);
SqlDataReader read_Email = cmd.ExecuteReader();
while (read_Email.Read())
{
 
email = read_Email.GetValue(i).ToString();
list_emails.Add(email);
//Add email to a arraylist
i = i + 1 - 1;
}
read_Email.Close();
con.Close();
//Close connection
foreach (string email_to in list_emails)
{
MailMessage mail = new MailMessage();
Attachment attach = new Attachment(fileAttachement.PostedFile.FileName);
mail.To.Add(email_to);
mail.From =
new MailAddress("kashi983@yahoo.com");
string Bcc = txtBcc.Text;
string cc = txtcc.Text;
mail.Subject = txtsubject.Text;
mail.Body =txtbody.Text;
SmtpClient smtp = new SmtpClient("SMTP Server");
smtp.Send(mail);
}
}
}






Output:-

 
To  
From  
Bcc  
cc  
Subject  
Body  
File to send:
 

 

Login to add your contents and source code to this article
share this article :
post comment
 

really very good sangeeta keep it up :)

Posted by Nikhil Kumar Sep 12, 2009
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor