Skip navigation.

« Long Time No Blog | Main | Back to School »

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("http://schemas.microsoft.com/ _
cdo/configuration/smtpauthenticate", "1")
objMail.Fields.Add("http://schemas.microsoft.com/ _
cdo/configuration/sendusername", "username")
objMail.Fields.Add("http://schemas.microsoft.com/ _
cdo/configuration/sendpassword", "password")
objMail.Fields.Add("http://schemas.microsoft.com/ _
cdo/configuration/sendusing", "2")
objMail.Fields.Add("http://schemas.microsoft.com/ _
cdo/configuration/smtpserverport", "465")
objMail.Fields.Add("http://schemas.microsoft.com/ _
cdo/configuration/smtpusessl", true)
objMail.Fields.Add("http://schemas.microsoft.com/ _
cdo/configuration/smtpconnectiontimeout", "60")
SmtpMail.SmtpServer = "smtp.umn.edu"
Try
SmtpMail.Send(objMail)
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 June 3, 2005 2:16 PM by westr015 | Comments (0) | TrackBack (0) U of M

Comments
Post a comment









Remember personal info?






Powered by Movable Type 4.25.