Sending advanced emails

Sending emails in dotnetnuke is very simple with the one hit method Mail.SendMail(…) living in the DotNetNuke.Services.Mail namespace. But if you need more options like integrating images in the mail or handling HTML-, Text parts and attachments you need the direct Mail stuff from the .NET Framework.


First thing we need is reading the Host settings, because we want to use the SMTP server which is configured in dnn:

string smtpServer = (string)DotNetNuke.Common.Globals.HostSettings["SMTPServer"];
string smtpAuthentication = (string)DotNetNuke.Common.Globals.HostSettings["SMTPAuthentication"];
string smtpUsername = (string)DotNetNuke.Common.Globals.HostSettings["SMTPUsername"];
string smtpPassword = (string)DotNetNuke.Common.Globals.HostSettings["SMTPPassword"];</pre>

Our goal is now sending an email with a text part, a HTML-Part which has the sitelogo integrated and an attachment. Don’t forget to add System.Net.Mail to your namespace usings!

Lets create the mail object and add some address information:

MailMessage mail = new MailMessage();

mail.From = new MailAddress("\"My Name\" <me@myaddress.com>");
mail.Subject = "Hello this mail is from dotnetnuke";

Now let us create our first part, the plain text part of our mail. (If you want a special encoding, change the null to a System.Text.Encoding type)

AlternateView av1 = AlternateView.CreateAlternateViewFromString("This is the plain text part",null,"text/plain");

Next is adding our HTML part as a second AlternateView with our logo inside. In your HTML, you use “cid: as the source of the image. Then you add a linked resource and set the ContentId to whatever you set in your HTML image source.:

string htmltext = "Hello folks! <br> This is my new logo:  <img src="\"cid:Logo\">";
AlternateView av2 = AlternateView.CreateAlternateViewFromString(htmltext, null, "text/html");
string logoFile = MapPath(PortalSettings.HomeDirectory + PortalSettings.LogoFile);
if (File.Exists(logoFile))
	LinkedResource linkedResource = new LinkedResource(logoFile);
	linkedResource.ContentId = "Logo";
	linkedResource.ContentType.Name = logoFile;
	linkedResource.ContentType.MediaType = "image/jpeg";

Now lets us add the AlternateViews to our mail and attach a file to it. Please be aware that the ASP.NET process (or the ASP.NET impersonated account) will need permission to read the file!

mail.Attachments.Add(new Attachment("c:\\temp\\example.txt"));</pre>

OK, Our mail is ready, now we can send it!

SmtpClient emailClient = new SmtpClient(smtpServer);
if (smtpAuthentication == "1")
	System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(smtpUsername, smtpPassword);
	emailClient.UseDefaultCredentials = false;
	emailClient.Credentials = SMTPUserInfo;

As you see, this is no big deal and hopefully you start now sending out marvelous designed emails with attachments and integrated images that are not suppressed by the customers email client. A good resource if you want to know more about this is the website http://www.systemnetmail.com

Total: 26 Comment(s)
Well, I never had the need to send advanced emails but I guess I will have to know. I saw something about it onhttps://cheapessayservice.net/our-services/movie-review/ but since I did not know anything about it, I was worried. This really helps, thanks!
Saturday, November 3, 2018 · reply ·
geile weiber sex
Visit https://hausfrauensex.net/geileweiber for your own free sexy chat experience with hot young local girls!
Tuesday, October 6, 2020 · reply ·
Sending emails in dotnetnuke is very easy with a single hit method Mail.SendMail(…) living in the DotNetNuke.Services.Mail namespace. In case you want more options such as images in the mail, Text parts, dealing HTML and attachments you should have the direct Mail stuff from.NET Framework. I try to know about a site which is https://www.toptenwritingservices.com/7dollaressay-com-review/ and if anyone have suggestion or want to share experience then please do it.
Monday, November 5, 2018 · reply ·
I am glad to read it. https://www.sdfsd.com
Wednesday, December 19, 2018 · reply ·
I am glad to read it. https://www.sdfsd.com
Sunday, January 20, 2019 · reply ·
Amazing blog with lots of information, thanks a lot for sharing this.
Wednesday, April 24, 2019 · reply ·
【丰胸产品】刘丽丽: https://1807614030.wixsite.com/fngzsite 那个时候我刚好失恋 ,很显然男人大多喜欢胸部大的 https://1807614030.wixsite.com/fngzgw 女生 ,那次失恋给我的打击很大 。我下定决心一定要丰胸 , https://1807614030.wixsite.com/fngzsite 也是很偶然找到粉嫩公主酒酿蛋 ,但粉嫩公主酒酿蛋没有让我失望 http://fngzmy.com
Thursday, July 4, 2019 · reply ·
how to give robux to friends 2019
Ask your friend what items he has for sale so you can buy one and donate Robux to him.
Friday, August 2, 2019 · reply ·
Ask your friend what items he has for sale so you can buy one and donate Robux to him. Record the names of the objects; Finding the name of an item is the fastest way to find it. https://robuxguide.club/how-to-give-robux-to-friends/
Friday, August 2, 2019 · reply ·
Lucille F. Parham
I just can’t stop reading this. Its so fresh, so filled with updates that I just didn’t know. https://summonerswar.io/
Saturday, January 11, 2020 · reply ·
https://styleup365.net/watchcartoononline/">akashic records of bastard magic instructor season 2
Tuesday, January 14, 2020 · reply ·
https://ask2human.com/">Customer Care Number
https://ask2human.com/listing/airtel-customer-care-number">Airtel Customer Care Number
https://ask2human.com/listing/bharat-gas-customer-care-number/">Bharat Gas Customer Care Number
https://ask2human.com/listing/hdfc-bank-customer-care-number/">HDFC Bank Customer Care Number
https://ask2human.com/listing/apple-customer-care-number/">Apple Customer Care Number
https://ask2human.com/listing/bata-customer-care-number/">Bata Customer Care Number
https://ask2human.com/listing/amazon-customer-care-number/">Amazon Customer Care Number
https://ask2human.com/listing/bookmyshow-customer-care-number/">BookMyShow Customer Care Number
https://ask2human.com/listing/caratlane-customer-care-number/">CaratLane Customer Care Number
https://ask2human.com/listing/chai-point-customer-care-number/">Chai Point Customer Care Number
https://ask2human.com/listing/cleartrip-customer-care-number/">Cleartrip Customer Care Number
https://ask2human.com/listing/croma-customer-care-number/">Croma Customer Care Number
https://ask2human.com/listing/expedia-customer-care-number/">Expedia Customer Care Number
https://ask2human.com/listing/ebay-customer-care-number/">Ebay Customer Care Number
https://ask2human.com/listing/firstcry-customer-care-number/">FirstCry Customer Care Number
https://ask2human.com/listing/flipkart-customer-care-number/">Flipkart Customer Care Number
https://ask2human.com/listing/goair-customer-care-number/">GoAir Customer Care Number
https://ask2human.com/listing/godaddy-customer-care-number/">GoDaddy Customer Care Number
https://ask2human.com/listing/goibibo-customer-care-number/">Goibibo Customer Care Number
https://ask2human.com/listing/goindigo-customer-care-number/">GoIndiGo Customer Care Number
https://ask2human.com/listing/grofers-customer-care-number/">Grofers Customer Care Number
https://ask2human.com/listing/homeshop18-customer-care-number/">HomeShop18 Customer Care Number
https://ask2human.com/listing/hotels-com-customer-care-number/">Hotels.com Customer Care Number
https://ask2human.com/listing/irctc-customer-care-number/">IRCTC Customer Care Number
https://ask2human.com/listing/ixigo-customer-care-number/">Ixigo Customer Care Number
https://ask2human.com/listing/jabong-customer-care-number/">Jabong Customer Care Number
https://ask2human.com/listing/jet-airways-customer-care-number/">Jet Airways Customer Care Number
https://ask2human.com/listing/koovs-customer-care-number/">Koovs Customer Care Number
https://ask2human.com/listing/lenskart-customer-care-number/">Lenskart Customer Care Number
https://ask2human.com/listing/limeroad-customer-care-number/">Limeroad Customer Care Number
https://ask2human.com/listing/makemytrip-customer-care-number/">MakeMyTrip Customer Care Number
https://ask2human.com/listing/myntra-customer-care-number/">Myntra Customer Care Number
https://ask2human.com/listing/naaptol-customer-care-number/">Naaptol Customer Care Number
https://ask2human.com/listing/nykaa-customer-care-number/">Nykaa Customer Care Number
https://ask2human.com/listing/ola-cabs-customer-care-number/">Ola Cabs Customer Care Number
https://ask2human.com/listing/pantaloons-customer-care-number/">Pantaloons Customer Care Number
https://ask2human.com/listing/paytm-customer-care-number/">PayTM Customer Care Number
https://ask2human.com/listing/nearbuy-customer-care-number/">NearBuy Customer Care Number
https://ask2human.com/listing/pepperfry-customer-care-number/">Pepperfry Customer Care Number
https://ask2human.com/listing/portea-medical-customer-care-number/">Portea Medical Customer Care Number
https://ask2human.com/listing/pvr-cinemas-customer-care-number/">PVR Cinemas Customer Care Number
https://ask2human.com/listing/quikr-customer-care-number/">Quikr Customer Care Number
https://ask2human.com/listing/redbus-customer-care-number/">Redbus Customer Care Number
https://ask2human.com/listing/shopclues-customer-care-number/">ShopClues Customer Care Number
https://ask2human.com/listing/shoppers-stop-customer-care-number/">Shoppers Stop Customer Care Number
https://ask2human.com/listing/rediff-customer-care-number/">Rediff Customer Care Number
https://ask2human.com/listing/snapdeal-customer-care-number/">Snapdeal Customer Care Number
https://ask2human.com/listing/xfinity-customer-care-number/">Xfinity Customer Care Number
https://ask2human.com/listing/usha-customer-care-number/">Usha Customer Care Number
https://ask2human.com/listing/oyo-rooms-customer-care-number/">Oyo Rooms Customer Care Number
https://ask2human.com/listing/zomato-customer-care-number/">Zomato Customer Care Number
https://ask2human.com/listing/spicejet-customer-care-number/">SpiceJet Customer Care Number
https://ask2human.com/listing/swiggy-customer-care-number/">Swiggy Customer Care Number
https://ask2human.com/listing/travelguru-customer-care-number/">Travelguru Customer Care Number
https://ask2human.com/listing/tripadvisor-customer-care-number/">TripAdvisor Customer Care Number
https://ask2human.com/listing/spectrum-customer-care-number/">Spectrum Customer Care Number
https://ask2human.com/listing/aakash-institute-customer-care-number/">Aakash Institute Customer Care Number
https://ask2human.com/listing/acc-limited-customer-care-number/">ACC Limited Customer Care Number
https://ask2human.com/listing/aol-customer-care-number/">Aol Customer Care Number
https://ask2human.com/listing/accu-chek-customer-care-number/">Accu-Chek Customer Care Number
https://ask2human.com/listing/urbanclap-customer-care-number/">UrbanClap Customer Care Number
https://ask2human.com/listing/acer-customer-care-number/">Acer Customer Care Number
https://ask2human.com/listing/intex-customer-care-number/">Intex Customer Care Number
https://ask2human.com/listing/bigbasket-customer-care-number/">BigBasket Customer Care Number
https://ask2human.com/listing/walmart-customer-care-number/">Walmart Customer Care Number
https://ask2human.com/listing/bharat-gas-customer-care-number/">Bharat Gas Customer Care Number
https://ask2human.com/listing/delhi-metro-rail-customer-care-number/">Delhi Metro Rail Customer Care Number
https://ask2human.com/listing/vijay-sales-customer-care-number/">Vijay Sales Customer Care Number
https://ask2human.com/listing/voltas-customer-care-number/">Voltas Customer Care Number
https://ask2human.com/listing/lg-customer-care-number/">LG Customer Care Number
https://ask2human.com/listing/rapido-bike-customer-care-number/">Rapido Bike Customer Care Number
https://ask2human.com/listing/jio-customer-care-number/">Jio Customer Care Number
https://ask2human.com/listing/yatra-customer-care-number/">Yatra Customer Care Number
https://ask2human.com/listing/verizon-customer-care-number/">Verizon Customer Care Number
Tuesday, February 11, 2020 · reply ·
Sophie Miller
Vielen Dank für die nützlichen Informationen! Ich half Ihren Rat! https://collegeadmissionscores.com/state/TX/
Thursday, March 26, 2020 · reply ·
Pretty! This was a really wonderful post. Thanks for providing these details. https://www.poolcreationsfl.com/copy-of-pool-resurfacing-sarasota
Wednesday, September 2, 2020 · reply ·
Summer Becky
Greetings! Very useful advice in this particular article! It's the little changes that make the most significant changes. Thanks a lot for sharing! http://www.capturealoha.com
Wednesday, September 2, 2020 · reply ·
ladies forum
You need to try https://hobbyladies.net/ladiesforum for your own free sexy chat pleasure with wonderful local girls!
Tuesday, September 22, 2020 · reply ·
sex in eisenstadt
Girls from https://nutten.at/burgenland are really the hottest around so check them today!
Thursday, October 1, 2020 · reply ·
Sophie Miller
Thank you for your work on the blog! You're doing a good job! https://dll.website/
Thursday, October 15, 2020 · reply ·
Sie sucht Sex Berlin
If you are looking for hot, young local girls you must vist – https://siesuchtsex.eu/berlin – for your own sexy chat pleasure!
Tuesday, October 27, 2020 · reply ·
Wednesday, November 11, 2020 · reply ·
T4M Darwin
If you are alone and want to meet some sexy young girls you must try free hot chat for sex contacts - https://t4mdarwin.com/">T4M Darwin
Tuesday, November 17, 2020 · reply ·


Torsten WeggenMy name is Torsten Weggen and I am CEO of indisoftware GmbH in Hanover, Germany. I'm into DNN since 2008. Before this, I did a lot of desktop stuff mainly coded with Visual Foxpro (see http://www.auktionsbuddy.de). 

I'm programmer, husband, father + born in 1965.

Please feel free to contact me if you have questions.

Latest Posts

DNN module development with Angular 2+ (Part 7)
6/10/2018 1:43 PM | Torsten Weggen
DNN module development with AngularJS (Part 6)
12/16/2016 7:00 AM | Torsten Weggen
DNN module development with AngularJS (Part 5)
12/16/2016 6:00 AM | Torsten Weggen
DNN module development with AngularJS (Part 4)
12/16/2016 5:00 AM | Torsten Weggen
DNN module development with AngularJS (Part 3)
12/16/2016 4:00 AM | Torsten Weggen
DNN module development with AngularJS (Part 2)
12/16/2016 3:00 AM | Torsten Weggen
DNN module development with AngularJS (Part 1)
12/15/2016 7:19 AM | Torsten Weggen
Blogging in DNN with Markdown Monster by Rick Strahl
11/27/2016 1:14 PM | Torsten Weggen
Creating a global token engine
11/18/2016 10:25 AM | Torsten Weggen
DnnImagehandler - Hot or not ?
2/21/2015 11:52 PM | Torsten Weggen

My Twitter

Keine News gefunden!