DotNetNuke Daily Tip #2 Mail.SendMail

Published Friday, June 23, 2006 10:32 AM

Check out all of the DotNetNuke Daily Tips from Chris Hammond.

DotNetNuke Daily Tip for 6/23/2006

Have you ever needed to send mail from one of your DotNetNuke modules? Here's the DotNetNuke method for sending off a message.

public static System.String SendMail ( System.String MailFrom , System.String MailTo , System.String Cc , System.String Bcc , DotNetNuke.Services.Mail.MailPriority Priority , System.String Subject , DotNetNuke.Services.Mail.MailFormat BodyFormat , System.Text.Encoding BodyEncoding , System.String Body , System.String Attachment , System.String SMTPServer , System.String SMTPAuthentication , System.String SMTPUsername , System.String SMTPPassword )

But what does that really mean? Here's a simple call to the mail function from a module.

Mail.SendMail("FROM@ADDRESS.COM", "TO@ADDRESS.COM", "", "THIS IS THE SUBJECT", "THIS IS THE MESSAGE BODY", "", "HTML", "", "", "", "" );

Could it get any simpler than that?

Actually it could! Here's another signature for sendmail

public static System.String SendMail ( System.String MailFrom , System.String MailTo , System.String Bcc , System.String Subject , System.String Body , System.String Attachment , System.String BodyType , System.String SMTPServer , System.String SMTPAuthentication , System.String SMTPUsername , System.String SMTPPassword )

 

Do you have a question about DotNetNuke? Perhaps I can answer it here as a Daily DotNetNuke Tip! Email chris.hammond at dotnetnuke.com  with your question! Be sure to put Daily Tips in the subject line.

Comments

# AndrewSeven said on Monday, June 26, 2006 2:35 PM

I hope there are some more overloads so that people don't always have to pass more empty parameters than they pass values.

# Kevin Donahoe said on Thursday, July 27, 2006 10:46 PM

So simple for sending mail in DNN but it is not working for me (version DNN 4.3.2) in certain respects. Do you see what is wrong with this code below ? The email actually goes out via the SMTP server and is delived to my email inbox but I wanted to make sure I had HTML that would do some nice line breaks using carriage returns and new lines. So the email goes out but the "carriage return and new line are not working. Everything appears on 1 line in my email inbox. string _EmailMsg1; string _EmailMsg2; _EmailMsg1 = "There has been Service and Help transaction activity. You can read and respond at ... "; _EmailMsg2 = "Portal Name"; string _EmailFullMsg = _EmailMsg1 + "\r\n" + _EmailMsg2; Regex _EmailExp = new Regex(_EmailFullMsg, RegexOptions.IgnoreCase); // Send out to the current user Mail.SendMail(PortalSettings.Email.ToString(), UserInfo.Email.ToString(), "", "An I-Receipt of transaction activity", Server.HtmlEncode(_EmailExp.ToString()), "", "html", "", "", "", ""); Thanks in advance for any C# thoughts you have on what is missing.

# Chris Hammond said on Thursday, July 27, 2006 11:40 PM

You should include <BR> for your linebreaks if you want to include HTML, not \r\n

# Kevin Donahoe said on Friday, July 28, 2006 12:02 AM

Hi, Hers is a updated attempt to get HTML line breaks when using DNN Send Mail. I actually thought this would work but still no line breaks on the email received in my inbox but the email itself does work. string _EmailMsg1; string _EmailMsg2; string _break = @"
"; _EmailMsg1 = "There has been Service and Help transaction activity. You can read and respond at ... "; _EmailMsg2 = PortalSettings.PortalAlias.HTTPAlias.ToString(); string _EmailFullMsg = _EmailMsg1 + _break + _EmailMsg2; string _EmailExp = new Regex(_EmailFullMsg, RegexOptions.Multiline).ToString(); // Send out to the current user Mail.SendMail(PortalSettings.Email.ToString(), UserInfo.Email.ToString(), "", "An I-Receipt of transaction activity", Server.HtmlEncode(_EmailExp), "", "html", "", "", "", "");

# Chris Hammond said on Friday, July 28, 2006 12:36 AM

Did you not see my above comment? You have to use actual HTML in your emails if you want it to show up.

# surender said on Tuesday, November 21, 2006 5:50 AM

What is the edifference between dotnetNuke.Common.sendNotifications() and Dotnetnuke.services.Mail.Mail.SendMail()

Please help me out

# Jonathan B. said on Sunday, March 04, 2007 1:19 PM

Here's one.  How do you set arbitrary SMTP headers?  

For example, assume I am creating a custom contact form.  I want the email to the contact destination to originate from a common website address.  But I want to dynamically set the Reply-To header to the email address provided by the person who submits the contact request.

Foreseeing this or other specific SMTP headers should not necessarily be in the purview of the SendMail API.  For these cases, it should be possible to specify any arbitrary SMTP header.  Is this currently possible?  If so, how?  If not, will it soon be?

# Vic Kumar said on Wednesday, April 18, 2007 10:52 PM

I believe SendMail is deprecated in DNN 4.  SendNotification is the replacement.

# Data Springs, Inc. said on Friday, July 27, 2007 7:03 PM

You might try Server.HtmlDecode(youremailmessage) in case the HTML hasn't already been decoded.

# AJ said on Wednesday, October 17, 2007 8:05 PM

I believe that Vic Kumar has the two methods the other way round. DotNetNuke.Common.Globals.SendMail is obsolete and has be replaced by DotNetNuke.Services.Mail.Mail.SendMail.

# cjepp said on Friday, May 09, 2008 3:45 PM

Do you know how to setup separate smtp server settings (with authentication) for each portal - so that they all don't have to use the settings in host menu?

# Chris Hammond said on Friday, May 09, 2008 4:01 PM

Cjepp, I don't believe that is possible

# Prashant said on Monday, June 30, 2008 2:34 AM

I am using the DotNetNuke.Services.Mail.Mail.SendMail method's overload with a replyto parameter. However the mail sent is always blank. I tried to change the format to text but no yield. I feel there is something wrong with my method call or implementation of method. The call i am making is :

DotNetNuke.Services.Mail.Mail.SendMail(mMailFrom, mMailTo, "", "", mReplyTo, DotNetNuke.Services.Mail.MailPriority.Normal, mSubject, DotNetNuke.Services.Mail.MailFormat.Html, System.Text.Encoding.UTF8, mBody, Nothing, _ServerName, "", _UserId, _UserPassword, False)

where in the variables contain values for various parameters. I have checked while debugging and all values are passed to method.

I am using DNN 4.08 framework.

Any body any resolution or hot fix ?

Pls. let me know. Its urgent!!!

Thanks in advance

Prashant

# Chris Hammond said on Tuesday, July 01, 2008 2:19 PM

Prashant, can you try without utilizing the Replyto, does it work in that case?

# Mehdi Bassiri said on Thursday, September 11, 2008 3:07 AM

Hi,

I need to know how I can attach a pdf file as a byte array insted of a string array?

Many Thanks

# Peter said on Friday, January 30, 2009 2:48 AM

Hi,

I am using SendMail to submit a form, and I want to include more than 1 attachment. Is that possible, and if Yes, how?

Please reply urgently!

# Fizgig said on Friday, July 30, 2010 2:57 PM

Does mailTo accept a semi-colon-delimited list of e-mail addresses, or a comma-delimited list, or just one address?

(I suppose an overload that accepts MailAddress or MailAddress[] or MailAddressCollection would have made too much sense.)

This Blog

Syndication