See this for sending mails

Sujit Patil replied to simi d at 03-Jul-08 11:58

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.


Click here to sign in and reply. You could earn money via our $500 contest just for being helpful.
  sending emails asynchronously. - simi d  03-Jul-08 09:10 9:10:08 AM
      you can send mail in sql server. - Deepak Ghule  03-Jul-08 09:19 9:19:15 AM
          sending mails in asp.net application - simi d  07-Jul-08 02:24 2:24:08 AM
          sending mails in asp.net application - simi d  07-Jul-08 03:04 3:04:00 AM
      asynchronous email - Umapathy Kaliaperumal  03-Jul-08 09:30 9:30:20 AM
          sending mails in asp.net application. - simi d  07-Jul-08 02:25 2:25:44 AM
      See this for sending mails - Sujit Patil  03-Jul-08 11:58 11:58:38 PM
          sending mails in asp.net application. - simi d  07-Jul-08 02:28 2:28:05 AM
      Send Email Async... - santhosh kumar  04-Jul-08 02:12 2:12:26 AM
          sending mails in asp.net application. - simi d  07-Jul-08 02:30 2:30:15 AM
View Posts