J-O Eriksson

Community Server on my mind

News

Subscribe via FeedBurner

Subscribe via email

<script type="text/javascript"><!-- google_ad_client = "pub-6305396639794057"; google_ad_width = 120; google_ad_height = 240; google_ad_format = "120x240_as"; google_ad_type = "text_image"; google_ad_channel ="5472463295"; google_color_border = "FFFFFF"; google_color_link = "0000FF"; google_color_bg = "FFFFFF"; google_color_text = "000000"; google_color_url = "008000"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

Subscribe in NewsGator Online

Subscribe in Bloglines

Add to Google

<script type="text/javascript" src="http://embed.technorati.com/embed/tb2ijzxn26.js"></script>

Blogs I read

Links

CS2: How to send mail from your CSModules

I sat and read Chris Hammond's blog today, he had a tip on sending mail from DotNetNuke, and I thought: "How do I send mail from a CSModule?". I remember downloading ScottW's CSModule Pack, and that it had a function to send mail when new users were registered etc. Looking through his code I found this (I've translated it from C# to VB):

Dim mail As MailMessage = New MailMessage

mail.To = _adminEmail
mail.Subject = subject
mail.Priority = priority
ail.From = _adminEmail
mail.BodyFormat = MailFormat.Text
mail.Body = body

EmailQueueProvider.Instance().QueueEmail(mail)

Just create a new System.Web.Mail.MailMessage object (if you do it in VS 2005 it will tell you that it's an obsolete class, but it works, and you need to use that since CS expects that class to be sent to the QueueEmail method), fill in the MailMessage's properties, and send it to CS's Email queue.

The _adminEmail, where to get the value for that? Well, you could use the CSContext.Current.SiteSettings.AdminEmailAddress property.

Of course one could always send mail directly via .NET Framework from the CSModule. But implementing CS built-in functions makes it follow the settings you do in the CS Interface and in the config files. Like changing the admin email, re-configuring the email job etc.

Comments

No Comments