Matt Posted February 4, 2015 Posted February 4, 2015 This will show you how to utilize official SMTP (Simple Mail Transfer Protocol) servers to send emails in your C# applications. All you need is a Hotmail, Yahoo, or Gmail email account. First, declare the usage of the System.Text and System.Net.Mail namespaces in your respective class. Then, create an object of the SmtpClient type. var client = new SmtpClient(); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential("Sending Email Account Address", "Sending Email Account Password"); Now, set the host and the port of your SmtpClient. client.EnableSsl = false; client.Host = ip; client.Port = port; Use this as a reference for such information. HOTMAIL: Maximum outgoing = 300 per day Port = 25 OR 465 Host = smtp.live.com (it seems to be down) Ssl = true GMAIL: Maximum outgoing = 500 per day Port = 465 Host = smtp.gmail.com Ssl = false; YAHOO: Maximum outgoing = 500 per day Port = 465 Host = smtp.mail.yahoo.com Ssl = false Now that we have our client all finished, we can begin to compose our email. var message = new MailMessage(); message.From = new MailAddress("sending email address"); message.To.Add("sending email"); message.Body = "The email itself"; message.Subject = "Subject of the email"; message.BodyEncoding = UTF8Encoding.UTF8; If you want to receive an email when the email fails, we can do that too. message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; All that's left to do is send the message. client.Send(message);
jcsnider Posted February 4, 2015 Posted February 4, 2015 Let the homegrown spam bots begin! But for real though, nice tutorial. I find myself looking for this code about once a year lol.
Richy Posted February 5, 2015 Posted February 5, 2015 Definitely cool, and even can be used in games for reform/registration purposes.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now