Click here to Skip to main content
13,254,154 members (59,529 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Having a little trouble with my Newsletter...

Let me explain: I have a sql table with my emails and nothing else and a sql table where i store the mails after they have been sendt, somehow the mails wont sent, but it will save the mails.

it is all set up in a formview.

protected void btnSendNewsLetter_Click(object sender, EventArgs e)
        TextBox subject = (TextBox)fvNewsletter.Row.FindControl("txtSubject");
        TextBox body = (TextBox)fvNewsletter.Row.FindControl("txtBody");
        string connection = WebConfigurationManager.ConnectionStrings["GreenCollaborationConnectionString"].ConnectionString;
        SqlConnection con = new SqlConnection(connection);
        SqlCommand comm = new SqlCommand("Select Email from MailingList", con);
        SqlDataAdapter da1 = new SqlDataAdapter(comm);
        GreenDataSet ds1 = new GreenDataSet();
        if(ds1.Tables[0].Rows.Count > 0)
            for (int i = 0; i <= ds1.Tables[0].Rows.Count - 1; i++)
                string email = ds1.Tables[0].Rows[i].ItemArray[0].ToString();
                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
                mail.From = new MailAddress("", "GreenCollaboration");
                mail.Subject = subject.Text;
                mail.SubjectEncoding = System.Text.Encoding.UTF8;
                mail.BodyEncoding = System.Text.Encoding.UTF8;
                mail.IsBodyHtml = true;
                mail.Body = body.Text;

i hope some1 can help me :)
Posted 8-Nov-12 6:16am
richcb 8-Nov-12 11:29am
You never send the message.

Check this:
terostar 8-Nov-12 11:31am
Okay, then how do i do that??
richcb 8-Nov-12 11:38am
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost"); smtp.Send(mail);
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need to use the SmtpClient class[^] to send the message(s).
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You're missing the bit that does the actual sending. Something like:

using (SmtpClient smtp = new SmtpClient())
    smtp.Host = "SMTPServer";

You'll need to later that to suit but it'll get you started.

By the way, you're not really creating th emails very efficiently. It is better to have a method that encapsulates the mailing process and takes, for instance, a collection of To addresses rather than one at a time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171114.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100