I think your problem is to send bulk emails. Try this code for the same;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net; using System.Net.Mail;
namespace email { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
static bool mailSent = false;
private void Form1_Load(object sender, EventArgs e) {
}
private void textBox4_TextChanged(object sender, EventArgs e) {
} public void senmail() { System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); msg.To.Add(textBox1.Text); msg.From = new MailAddress(textBox2.Text, "resume", System.Text.Encoding.UTF8); msg.Subject = textBox3.Text; msg.SubjectEncoding = System.Text.Encoding.UTF8; msg.Body = textBox4.Text; msg.BodyEncoding = System.Text.Encoding.UTF8; msg.IsBodyHtml = false; msg.Priority = MailPriority.High; SmtpClient client = new SmtpClient(); client.Credentials = new System.Net.NetworkCredential(textBox2.Text, textBox5.Text); client.Port = 587; client.Host = "smtp.gmail.com"; client.EnableSsl=true; client.SendCompleted +=new SendCompletedEventHandler(client_SendCompleted); object userstate=msg; try { client.SendAsync(msg,userstate); } catch(System.Net.Mail.SmtpException ex) { MessageBox.Show(ex.Message,"sending error"); } } public void client_SendCompleted(object sener,AsyncCompletedEventArgs e) { MailMessage mail=(MailMessage)e.UserState; if (e.Error != null) { MessageBox.Show("error"); } else { MessageBox.Show("Message sent"); } mailSent=true; }
private void button1_Click(object sender, EventArgs e) { this.senmail(); }
private void textBox2_Leave(object sender, EventArgs e) { if (textBox2.Text != "") { label5.Visible = true; textBox5.Visible = true; } } } }
I have worked with this... its working..
Also look at these links where they have provided details of the same;
http://www.sqlteam.com/article/sending-smtp-mail-using-a-stored-procedure
http://www.codeproject.com/KB/IP/smartmassemail.aspx
http://www.csharphelp.com/archives4/archive637.html
Best Luck!!!!!!!!!!!!! Sujit. |