There really isn't a lot on the net about this, and the material I did find was lacking. So here is my code block for sending emails using ASP.Net System.Mail class passing in credentials.
You will need the following using statements at the top, System.Web.Mail and this is for dotnet 2.0 or 3.5 frameworks.
MailMessage message = new MailMessage();
message.From = new MailAddress(@"Someone@url.com", "Someones Name");
message.To.Add(new MailAddress("SendingTo@url.com"));
message.Attachments.Add(new Attachment(@"C:\AttachmentLocation\"));
message.Subject = "Subject Line";
message.Body = "Contents of Email";
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("Username","Password");
client.Host = "smtp.mywebsite.com";
client.Port = 25;
client.Send(message);
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5