Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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);
 
        con.Open();
 
        SqlCommand comm = new SqlCommand("Select Email from MailingList", con);
        SqlDataAdapter da1 = new SqlDataAdapter(comm);
        GreenDataSet ds1 = new GreenDataSet();
        da1.Fill(ds1);
        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("noreply@GreenCollaboration.com", "GreenCollaboration");
                mail.To.Add(email);
                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 Smile | :)
Posted 8-Nov-12 5:16am
Comments
richcb at 8-Nov-12 11:29am
   
You never send the message.
 
Check this: http://social.msdn.microsoft.com/forums/en/netfxnetcom/thread/a75533eb-131b-4ff3-a3b2-b6df87c25cc8/
terostar at 8-Nov-12 11:31am
   
Okay, then how do i do that??
richcb at 8-Nov-12 11:38am
   
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost"); smtp.Send(mail);
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to use the SmtpClient class[^] to send the message(s).
  Permalink  
Rate this: bad
good
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";
    smtp.Send(mail);
}
 
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.
  Permalink  

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

  Print Answers RSS
0 CPallini 375
1 Sergey Alexandrovich Kryukov 370
2 BillWoodruff 314
3 George Jonsson 274
4 OriginalGriff 257
0 OriginalGriff 5,030
1 CPallini 4,115
2 Sergey Alexandrovich Kryukov 3,554
3 George Jonsson 2,826
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2014
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