Jill-Connie Lorentsen
Top achievements
Rank 1
Jill-Connie Lorentsen
asked on 13 May 2013, 11:04 AM
I want to create an e-mail that the user can edit and then send. The e-mail has a defaut body, which can be edited in a RadEditor. When the user clicks a button, the e-mail is created like this:
I enter a text into the RadEditor like this:
The problem is that the formatting is displays as text in the e-mail.
If I use
Any suggestions?
Regards, Jill-Connie
function OnClientButtonClicking(sender, args) { var button = args.get_item(); if (button.get_commandName() == "SendEmail") { var emailaddress = document.getElementById("EmailAddress").value; var subject = document.getElementById("EmailSubject").value; var editor = $find("<%=RadEditorEmailBody.ClientID%>"); var body = editor.get_html(); window.location = "mailto:" + emailaddress + "?subject=" + subject + "&body=" + body; } }I enter a text into the RadEditor like this:
string body = string.Empty;body += string.Format("This is the message to send.<br />");body += string.Format("It contains various information<br />");body += string.Format("<br />");RadEditorEmailBody.Content =body;The problem is that the formatting is displays as text in the e-mail.
If I use
var body = editor.get_html(true); in the javascript the result is the same, but the text is clipped if I enter a special character like §, ø, etc.Any suggestions?
Regards, Jill-Connie
4 Answers, 1 is accepted
0
Elliott
Top achievements
Rank 2
answered on 13 May 2013, 03:32 PM
yes, because that is pretty much the application I developed
1 - use the Content property as the Body (which I notice you are already doing)
2 - determine which Tools will not be needed and Remove them in the Page Load event handler
3 - if you want to use style sheets you'll need to manually identify the classes used - and pump in the corresponding style sheet text
4 - include a textbox so the user can send her(him) self a test email before emailing the actual recipient
if you've never generated email from a web site - to get images into the body of an email you may need to use AlternateViews
1 - use the Content property as the Body (which I notice you are already doing)
2 - determine which Tools will not be needed and Remove them in the Page Load event handler
3 - if you want to use style sheets you'll need to manually identify the classes used - and pump in the corresponding style sheet text
Imports System.Collections.GenericImports System.IOImports System.TextImports System.Text.RegularExpressionsPublic Class CSSParser Private Shared AnArray As String() Private _aString As String Private StyleSheets As List(Of String) Private _alist As SortedList(Of String, StyleClass) Public Property AList As SortedList(Of String, StyleClass) Get Return Me._alist End Get Set(value As SortedList(Of String, StyleClass)) Me._alist = value End Set End Property Public Function BuildListofStyles(FilePath As String) As String() Dim AnArray As String() Me.StyleSheets = New List(Of String) Me._alist = New SortedList(Of String, StyleClass) Me.StyleSheets.Add(FilePath) AnArray = ParseStyleSheet(FilePath) Return AnArray End Function Private Function ParseStyleSheet(FilePath As String) As String() Dim strBody, AString, SecondString, ThirdString As String Dim i, j As Integer Dim sb As StringBuilder = Nothing Dim aryStyle, aryClass As String() sb = New StringBuilder(String.Empty) strBody = RemoveExtraneousCharacters(File.ReadAllText(FilePath)) AnArray = strBody.Split("}") For i = 0 To AnArray.Length - 2 aryStyle = AnArray(i).Split("{") If aryStyle(0).Length > 0 Then AString = aryStyle(0).Remove(0, 1) sb.Append(AString) sb.Append(",") End If Next _aString = sb.ToString j = _aString.LastIndexOf(",") SecondString = _aString.Remove(j) ThirdString = _aString.Remove(j - 1) aryClass = SecondString.Split(",") Return AnArray End Function Private Function RemoveExtraneousCharacters(strBody As String) As String Dim strTemp As String Dim cnstRegEx As String = "(/\\*(.|[\r\n])*?\\*/)|(//.*)" Dim regExpr As Regex = Nothing strTemp = strBody regExpr = New Regex(cnstRegEx) strTemp = regExpr.Replace(strTemp, "") strTemp = strTemp.Replace("\r", "").Replace("\n", "") Return strTemp End Function Public Function BuildCSSString(ASet As SortedSet(Of String), AnArray As String()) As String Dim sb As StringBuilder = Nothing Dim AClass As String = String.Empty sb = New StringBuilder("<style type=") sb.append(Chr(34)) sb.Append("text/css") sb.Append(Chr(34)) sb.Append(" >") sb.Append(vbCrLf) For Each AClass In ASet sb.Append(GetCSSClass(AnArray, AClass)) Next sb.Append(vbCrLf) sb.Append("</style>") Return sb.ToString End Function Public Function GetCSSClass(aryClass As String(), AClass As String) As String Dim sb As StringBuilder = Nothing Dim i, j As Integer Dim aryStyle, aryAttr As String() sb = New StringBuilder(String.Empty) For i = 0 To aryClass.Length - 1 aryStyle = aryClass(i).Split("{") If (aryStyle(0).Trim() = "." & AClass) Then sb.Append(".") sb.Append(AClass) sb.Append(" { ") aryAttr = aryStyle(1).Split(";") For j = 0 To aryAttr.Length - 1 sb.Append(aryAttr(j).Trim()) sb.Append("; ") Next sb.Append("} ") End If Next Return sb.ToString End Function Public Class StyleClass Private _name As String = String.Empty Private _attributes As New SortedList(Of String, String) Public Property Name As String Get Return _name End Get Set(value As String) _name = value End Set End Property Public Property Attributes As SortedList(Of String, String) Get Return _attributes End Get Set(value As SortedList(Of String, String)) _attributes = value End Set End Property End ClassEnd Class4 - include a textbox so the user can send her(him) self a test email before emailing the actual recipient
if you've never generated email from a web site - to get images into the body of an email you may need to use AlternateViews
0
Jill-Connie Lorentsen
Top achievements
Rank 1
answered on 14 May 2013, 08:24 AM
Thank you for your reply and the code.
I am afraid I need a bit more help... I think this is more than what I need, and I have difficulties seeing which parts that can be omitted. I don't use style sheets.
Could you please give me an example of usage of this class in my context? RadEditor.Content = ???
Thank you very much!
Regards, Jill-Connie Lorentsen
I am afraid I need a bit more help... I think this is more than what I need, and I have difficulties seeing which parts that can be omitted. I don't use style sheets.
Could you please give me an example of usage of this class in my context? RadEditor.Content = ???
Thank you very much!
Regards, Jill-Connie Lorentsen
0
Elliott
Top achievements
Rank 2
answered on 14 May 2013, 01:17 PM
Jill
you can completely ignore the class above if you don't use style sheets
to remove Tools, in the Page Load, if not PostBack
then all you need to do is set mail message.Body = Rad Editor.Content
make sure you set IsHTML to true if you include any styling icons
the control generates <span> tags which don't work in Text email
the Managers (Document Manager,ImageManager, etc.) require a location on the web site with write privileges to put images, etc to upload
you can completely ignore the class above if you don't use style sheets
to remove Tools, in the Page Load, if not PostBack
myRadEditor.EnsureToolsFileLoaded()For Each etGroup As EditorToolGroup In myRadEditor.Tools dim etBase As List(Of EditorToolBase) Dim etBase As List(Of String)=etGroup.GetAllTools For i = 0 To etBase.Count - 1 If DirectCast(etBase(i), EditorTool).Name = "whatever" etGroup.Tools.Remove(etBase(i)) End If Next NextPrintAjaxSpellCheckFindAndReplaceSelectAllCutCopyPastePasteStripUndoRedoImageManagerDocumentManagerFlashManagerMediaManagerTemplateManagerLinkManagerUnlinkSuperscriptSubscriptInsertParagraphInsertGroupboxInsertHorizontalRuleInsertDateInsertTimeFormatCodeBlockFormatBlockFontNameRealFontSizeAbsolutePositionBoldItalicUnderlineStrikeThroughJustifyLeftJustifyCenterJustifyRightJustifyFullJustifyNoneIndentOutdentInsertOrderedListInsertUnorderedListToggleTableBorderXhtmlValidatorForeColorBackColorApplyClassFormatStripperInsertSymbolInsertTableInsertFormElementInsertSnippetImageMapDialogInsertCustomLinkConvertToLowerConvertToUpperZoomModuleManagerToggleScreenModeAboutDialogthen all you need to do is set mail message.Body = Rad Editor.Content
make sure you set IsHTML to true if you include any styling icons
the control generates <span> tags which don't work in Text email
the Managers (Document Manager,ImageManager, etc.) require a location on the web site with write privileges to put images, etc to upload
0
Jill-Connie Lorentsen
Top achievements
Rank 1
answered on 14 May 2013, 01:35 PM
Thanks, it works from code behind, but I would like to do it with javascript on the client side
Is there a way?
Regards, Jill-Connie
<script type = "text/javascript"> function OnClientButtonClicking(sender, args) { var button = args.get_item(); //alert(button.get_commandName()); if (button.get_commandName() == "SendProgramByEmail") { var emailaddress = document.getElementById("HiddenEmailAddress").value; var subject = document.getElementById("HiddenEmailSubject").value; //var body = document.getElementById("HiddenEmailBody").value; var editor = $find("<%=RadEditorEmailBody.ClientID%>"); var body = editor.get_html(true); window.location = "mailto:" + emailaddress + "?subject=" + subject + "&body=" + body; } } </script>Is there a way?
Regards, Jill-Connie