Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone, I need a way to send mass emails containing some kind of information from asp.net mvc 5, i know how to do this with SmtpClient class, but doesn't work with various directions, please, need your help, thanks...
Posted
Comments
[no name] 26-Sep-14 17:00pm    
If you already know how to do this, then what is the question?
[no name] 30-Sep-14 0:42am    
if you know SmtpClient, why dont you just go with that. I have used it. If you need any assistance in that i can help :)

1 solution

Well, that was definetly easy, the only thing that I needed to do is to make a "MailAdressCollection" and then insert all the emails, and then with a foreach send to each one of the addressess in my Collection, below is my code:
C#
static void Main(string[] args)
        {
            MailAddressCollection collection = new MailAddressCollection();
            collection.Add("xxx@xxx.xx");
            collection.Add("xxx@xxx.xx");

            foreach (var item in collection)
            {
                var to = item;
                var from = new MailAddress("xxx@xxx.xx");
                var message = new MailMessage(from, to);
                message.Subject = "Contract";
                message.Body = @"Hello, you and your team have been classified to go directly to World Finals for good performance in previous competitions and cups, Sincerely, ICPC Team.";
                // Use the application or machine configuration to get the 
                // host, port, and credentials.
                var client = new SmtpClient("xxx");
                client.Credentials = new NetworkCredential("xxx", "xxxx");
                //client.EnableSsl = true;


                Console.WriteLine("Sending an e-mail message to {0} at {1} by using the SMTP host={2}.",
                    to.User, to.Host, client.Host);
                try
                {
                    client.Send(message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception caught in CreateTestMessage3(): {0}",
                          ex.Message);
                }
            }
        }
    }
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900