I’ve been doing some testing of email enabled lists, and I needed to send quite a lot of emails, so I wrote a little console app to do it. Here’s the core of the code I used, in case I need it again, or it’s useful to someone. It uses System.Net.Mail:
SmtpClient smtp = new SmtpClient(@"vm-moss2007.virtual.local"); for (int i = 1; i <= 100; i++) { MailMessage message = new MailMessage("administrator@virtual.local", <a href="mailto:testlist@sharepoint.virtual.local">testlist@sharepoint.virtual.local</a>); message.Subject = string.Format("Message {0}", i); message.Body = string.Format("This is message '{0}'", i); Console.WriteLine("Sending {0}", i); smtp.Send(message); }
There are built in classes to do just about anything including email. Emailing with attachments isn’t as hard as you might think.
These days most of the ISP require an authentication to send en emila with SMTP.
Here is a code example how to do it in .NET 3.5
http://www.kozlenko.info/2009/01/13/sending-e-mail-from-c-net-35-application-using-smtp-authentication/
Very simple and straight to the point. I have always appreciated how easy the framework developers have made it to send mail.
Max – Thanks, nice example. Yeah, I was testing on a dev machine with no authentication requirements.
Garry – yup, agreed. Even the authentication that Max mentioned is pretty straight forward.