Secure the Email in Your .NET Apps with SSL Email Components
page 11 of 14
by John Alessi
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 49332/ 83

Sending Mail over an SSL Connection

The following sample code demonstrates how to send Internet email over a secure connection to an SSL enabled SMTP server.

VB.Net Sample
Dim objSMTP As New SMTP
objSMTP.SMTPServers.Add("mail.domain.com", 465)
Dim objSSL As New SSL
objSMTP.Connect(objSSL.GetInterface())
Dim objMessage As New EmailMessage( _
    "recipient@domain.com", "sender@domain.com", _
    "Subject", "Body text", BodyPartFormat.Plain)
objSMTP.Send(objMessage)
objSMTP.Disconnect()
C# Sample
</span></pre><pre><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 10.0pt">SMTP objSMTP = new SMTP();<o:p></o:p></span></pre><pre><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 10.0pt">objSMTP.SMTPServers.Add("mail.domain.com", 465);<o:p></o:p></span></pre><pre><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 10.0pt">SSL objSSL = new SSL();<o:p></o:p></span></pre><pre><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 10.0pt">objSMTP.Connect(objSSL.GetInterface());<o:p></o:p></span></pre><pre><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 10.0pt">EmailMessage objMessage = new EmailMessage(<o:p></o:p></span></pre><pre><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 10.0pt"><span style="mso-tab-count: 1">               </span>"recipient@quiksoft.com", "sender@domain.com", <o:p></o:p></span></pre><pre><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 10.0pt"><span style="mso-tab-count: 1">               </span>"Subject", "Body text", BodyPartFormat.Plain);<o:p></o:p></span></pre><pre><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 10.0pt">objSMTP.Send(objMessage);<o:p></o:p></span></pre><pre><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 10.0pt">objSMTP.Disconnect();<span style="mso-spacerun: yes">   </span><o:p></o:p></span></pre>


<span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 14.0pt; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-weight: bold; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">

 

Yeah, that's it, pretty easy huh?  Communications with the mail server will take place on port 465 which is the standard port for SMTP data traveling over SSL connections.  The SSL plug-in is interfaced with the SMTP component during the call to Connect(), and the email components take over from there.


View Entire Article

User Comments

Title: NO TEXT WRAP!   
Name: Stuart Welwood
Date: 2006-02-21 2:07:44 PM
Comment:
The text of this article does not wrap - VERY difficult to read!

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-26 11:35:46 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search