Home
Manage Your Code
Snippet: Send an email using authentication (C#)
Title: Send an email using authentication Language: C#
Description: Send an email using authentication Views: 291
Author: Als James Date Added: 11/11/2008
Copy Code  
1public Boolean Send(String subject, String body)
2        {
3            try
4            {
5                MailMessage message = new MailMessage(
6                    m_from, m_to, subject, body);
7
8                NetworkCredential creds = new NetworkCredential(m_smtp_username,
9                    m_smtp_password);
10
11                SmtpClient smtpClient = new SmtpClient();
12                smtpClient.Host = m_smtp_server;
13                smtpClient.Port = m_smtp_port;
14
15                smtpClient.UseDefaultCredentials = false;
16                smtpClient.Credentials = creds;
17
18                smtpClient.Send(message);
19
20                return true;
21            }
22            catch (SmtpException)
23            {
24                return false;
25            }
26        }