ColdFusion & .NET: Send an Email
Today's post in the ColdFusion & .NET series covers a fairly simple task: sending an email. This is very easy to do in both languages. The examples below show you how to send a text based email in each language.
In ColdFusion you use the CFMAIL tag to send off an email. In the example below I have included the server attributes as part of the tag. If you do not supply those when using the tag, ColdFusion will use the information that is setup in the ColdFusion Administrator to connect to the SMTP server.
<code lang="cfm[lines]"><cfmail from="Some Name <firstname.lastname@example.org>" subject="Your Test Email" to="email@example.com"><br></br> Hello test email.<br></br></cfmail>``` Now the code in C#:
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.Subject = "Your Test Email";
message.From = new System.Net.Mail.MailAddress("firstname.lastname@example.org");
message.Body = e.ToString();
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("mail.someserver.com");
smtp.Credentials = new NetworkCredential("username", "password");
In C# you must also include the following library:
<code lang="csharp[lines]">using System.Net.Mail;