Skip navigation.

June 2005

Secure E-mail with ASP.NET

Since the University is phasing out their open mail relay in July, I've been looking for a way to send e-mail from my web forms through the secure mail server. I finally happened across a solution using a Windows library called CDONTS, which has a lot of this type of functionality.

Here's a function to send mail using VB.NET, but the methods are almost identical in C#. You have to import the System.Web.Mail namespace for this to work (using <%@ Import Namespace="System.Web.Mail" %>)

Function SendMail(strFrom, arrTo, strSubject, strBody)
Dim objMail As New MailMessage()
objMail.From = strFrom
objMail.To = Join(arrTo, ",")
objMail.Subject = strSubject
objMail.Body = strBody
objMail.Fields.Add(" _
cdo/configuration/smtpauthenticate", "1")
objMail.Fields.Add(" _
cdo/configuration/sendusername", "username")
objMail.Fields.Add(" _
cdo/configuration/sendpassword", "password")
objMail.Fields.Add(" _
cdo/configuration/sendusing", "2")
objMail.Fields.Add(" _
cdo/configuration/smtpserverport", "465")
objMail.Fields.Add(" _
cdo/configuration/smtpusessl", true)
objMail.Fields.Add(" _
cdo/configuration/smtpconnectiontimeout", "60")
SmtpMail.SmtpServer = ""
Return True
Catch ex As Exception
Return False
End Try
End Function

You need to pass the function four arguments:

1. strFrom = the reply to address
2. arrTo = an array of addresses to send the message to
3. strSubject = the subject text of the e-mail
4. strBody = the body text of the e-mail

Inside the function, you'll need to set "username" and "password" to a valid x500 username and password.

Posted on 2:16 PM by westr015 U of M

June 2005

Long Time No Blog

After a busy spell (excuses, excuses) I'm attempting to get back into the blogging habit. I've finally got some time to try out some ideas with MovableType templates and UThink RSS feeds. More to come.

Posted on 3:39 PM by westr015 Administrivia

Powered by Movable Type 4.31-en.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.