Monodeep
Monodeep

Reputation: 1392

sending email to users contact list?

i have an application to retrieve an users contact list in a gridview...how do i send email to all the users from the users contact list??

Steps:-

1.User enters hi/her email id and password. 2.Clicks on send invites. 3.The button click event should send invitation email to all the contacts in users contact list.[ how to do the 3rd step??]

Upvotes: 1

Views: 564

Answers (2)

William Xifaras
William Xifaras

Reputation: 5312

I posted the code to send off a batch (List) of e-mails. Looping through a gridview row collection is fairly straightforward and you should check out that link I provided. Here is a small code snippet to get you started.

        List<string> emails = new List<string>();
        foreach (GridViewRow row in gv.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                emails.Add(row.Cells[0].Text); // provided that index 0 is the e-mail address
            }
        }

        // fire off the e-mails

Upvotes: 1

William Xifaras
William Xifaras

Reputation: 5312

public void SendEmail(List<string> emailAddresses)
    {
        try
        {
            MailMessage mail = new MailMessage();

            mail.From = new MailAddress("Some From Address");

            foreach (string email in emailAddresses)
            {
                mail.To.Add(email);
            }

            mail.Subject = "Some Message Title";
            mail.Body = "Some Message Body";

            SmtpClient smtp = new SmtpClient("Some Relay Server");

        }
        catch (SmtpFailedRecipientException exc)
        {
            // Log Exception.
        }
    }

Upvotes: 0

Related Questions