UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
2 Pages V  1 2 >  (Go to first unread post)
   Reply to this topicStart new topic
> Line Wrap In Email Body - Html In C#    
 
   
tina t
post Jan 7 2020, 03:06 PM
Post#1



Posts: 6,693
Joined: 11-November 10
From: SoCal, USA


hi folks, one of the IT folks is using C# to take data from an Access db and use it to send emails within the company, using Outlook (2016, i think). i'm providing him with a query in Access that he loops through in C# to produce emails - one email per query record. so far so good.

here's the problem: the text in the body of the emails he generates won't wrap.

i can't figure it out, because i generate emails using VBA, and the text in the body of those emails automatically wraps as you would expect it to, just depending on the size of the email window whenever an email is being viewed.

is there something that needs to be done in C#, or in the HTML in C#, to allow a normal linewrap? or is there something the might be preventing a normal linewrap?

i know the above is a floppy kind of question, sorry! but i don't know anything about C# and very little about HTML, so i'm floundering re terminology, etc. any help, suggestions, links to other sites, etc, are all greatly appreciated.

tia,
tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
jleach
post Jan 7 2020, 03:27 PM
Post#2


UtterAccess Administrator
Posts: 10,589
Joined: 7-December 09
From: St. Augustine, FL


Hi Tina - I can't think of anything offhand that would cause this as default behavior.

If the format of the email is set to plaintext instead of html, it should wrap the text automatically, and if it's html, it should also wrap the text automatically.

The only thing that comes to mind is that the person generating the emails has some sort of style rule in place for the resultant html indicating it specifically NOT to wrap the text (some sort of CSS overflow setting maybe), but that would almost have to be explicitly set.

Maybe someone else will have an idea, but it really sounds like something on their end rather than anything you can/should be doing in an Access query.


--------------------
Jack D. Leach
Founder & CEO
Dymeng Services Inc.
Business Software Solutions
Go to the top of the page
 
theDBguy
post Jan 7 2020, 04:18 PM
Post#3


UA Moderator
Posts: 78,504
Joined: 19-June 07
From: SunnySandyEggo


Hi Tina. I agree with Jack. The default behavior is to wrap. If it's not wrapping, you could check if the email message is being constructed using HTML tags. If so, look for "nowrap" attributes anywhere in the C# constructed email message/body.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
tina t
post Jan 7 2020, 05:59 PM
Post#4



Posts: 6,693
Joined: 11-November 10
From: SoCal, USA


thanks for responding, Jack and DBguy. :) i didn't think the issue was in my Access query or the Access data itself. i'm kinda asking about this issue on behalf of the IT guy. i've just asked him to email me the C# code he's using to generate the emails. i'll post it, and maybe one of you or somebody else will spot something that shouldn't be there, or should be and isn't.

tia, tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
jleach
post Jan 7 2020, 07:31 PM
Post#5


UtterAccess Administrator
Posts: 10,589
Joined: 7-December 09
From: St. Augustine, FL


A copy of the raw email might actually be better, if you can get that.

--------------------
Jack D. Leach
Founder & CEO
Dymeng Services Inc.
Business Software Solutions
Go to the top of the page
 
tina t
post Jan 9 2020, 09:15 PM
Post#6



Posts: 6,693
Joined: 11-November 10
From: SoCal, USA


hi Jack, thanks for responding. not sure what you mean by "raw email", though. my guy did get the line wrap to work, so that issue is fixed.

the remaining problem is that the line is breaking anywhere within a word when the end of the available space is reached, rather than keeping whole words - and punctuation that immediately follows, such as periods and commas - together.

any suggestions for what might work in Outlook, Office 365? i've asked him for his latest code again, so that i can post it if anyone asks.

tia,
tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
jleach
post Jan 10 2020, 05:20 AM
Post#7


UtterAccess Administrator
Posts: 10,589
Joined: 7-December 09
From: St. Augustine, FL


Hi Tina - it sounds like despite the "wrap" being fixed, there's still a similar/related underlying problem.

By "raw" email, I basically meant a copy of the email. There should be a way (somehow) to get the raw text of an email through various email clients, though I'm not sure offhand how. Or, if you wanted to forward the email to someone to take a look outside the forums, that'd be a means to do so as well (I can do so if you want to forward the email to me: PM me for my email address if you want).


--------------------
Jack D. Leach
Founder & CEO
Dymeng Services Inc.
Business Software Solutions
Go to the top of the page
 
JonSmith
post Jan 10 2020, 05:32 AM
Post#8


UtterAccess VIP
Posts: 4,073
Joined: 19-October 10



QUOTE
any suggestions for what might work in Outlook, Office 365? i've asked him for his latest code again, so that i can post it if anyone asks.


I'm happy to check it once you send it over. I'm mainly a C# developer these days and have alot of experience building emails in it now.

That along with the html of the email and I'm sure we can figure this out smile.gif
If you have an equivalent email you built in VBA that doesnt have these issues that could also be great along with the code used.

JS
Go to the top of the page
 
tina t
post Jan 10 2020, 01:44 PM
Post#9



Posts: 6,693
Joined: 11-November 10
From: SoCal, USA


thanks Jack and Jon for responding. i'm still waiting to hear from my IT guy. i'll post back when i have something. :) tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
tina t
post Jan 10 2020, 05:01 PM
Post#10



Posts: 6,693
Joined: 11-November 10
From: SoCal, USA


okay, guys, here's my IT guy's code that is running. and just to recap: line wrap is working, so the text doesn't run off the right side of the window anymore, when you're looking at the "sent" email. but the text breaks at the right side of the displayed window size, anywhere within a word or between a word and immediately trailing commas, periods, etc.

CODE
Calling method:
     const bool isBold = true;
                const bool isPreserveWhiteSpace = false;
                const bool isReplaceByNBSP = true;
                const bool isReplaceNewLine = true;
                const string wordBreakFlag = "A";

                string recipient, body;
                List<EmailInfo> infos;
                EmailInfo info;
                List<string> list;
                string subject;
                foreach (var item in dictionary)
                {
                     // item.Key: recipient string (email address)
                    // item.Value: List<EmailInfo> of data items to send
                    // where EmailInfo is a class    
                    recipient = item.Key;

                    infos = item.Value;
                    list = new List<string>();
                    foreach (EmailInfo i in infos)
                        list.Add(i.EmailData);
                    // list example:
                    //   Example: "the little engine that could"
                    //            "go up the hill"
                    
                    body = GetHTMLBody
                     (list, "DarkBlue", "Courier New", null,
                      isBold, isPreserveWhiteSpace, isReplaceByNBSP,
                      isReplaceNewLine, wordBreakFlag);
                    info = infos.FirstOrDefault();
                    subject = info == null ? EmailSubject
                        : info.SubjectLine ?? EmailSubject;

                    UtEmail.SendEmailNoAttachOneRecipV3
                    (recipient, subject,
                     body, null, null, true);  
                }

GetHtmlBody:
                public string GetHTMLBody(List<string> list, string fontColor = null,  
             string fontFamily = null, string fontSize = null,
             bool isBold = false, bool isPreserveWhiteSpace = false,
             bool isReplaceByNBSP = false, bool isReplaceNewLine = false,
             string workBreakFlag = "N")
        {   // list should have no embedded carriage returns or line feeds
            /* http://www.w3schools.com/cssref/pr_text_white-space.asp
             * Whitespace, such as line breaks, spaces, and tabs,
             * is collapsed by default in HTML documents.
             * You can use the nonbreaking space entity (&nbsp;)
             * to add extra spaces to an object when the white-space property
             * is set to normal or nowrap. You can add extra line breaks
             * using the br element.
             * http://kyleschaeffer.com/development/CSS-font-size-em-vs-px-vs-pt-vs/
             * http://www.quackit.com/html/codes/html_font_size_code.cfm
             * http://www.w3schools.com/colors/colors_names.asp
             * fixed fonts: Courier New, Lucida Sans Typewriter
             */  
           // const string quote = "\"";
            StringBuilder sb = new StringBuilder();
            sb.Append("<HTML>");
            string color = fontColor == null ? "Black" : fontColor;
            // in this method, always set color:          
            sb.Append("<body style='color:" + color + ";");
            if (fontFamily != null)
                sb.Append("font-family:" + fontFamily + ";"); // example: Courier New
            if (fontSize != null)
                sb.Append("font-size:" + fontSize + ";"); // example: 0.25in
            if (isBold)
                sb.Append("font-weight:bold;");
            if (isPreserveWhiteSpace)
                sb.Append("white-space: pre;");
            switch(workBreakFlag)
            {
                case "A":  
                    sb.Append("word-break:break-all;");  (Works in Outlook, but break up words.  Example: ‘plain’ might end up as
                                                     pl
                    ain (on next line)
                    break;
                case "W": // future: overflow-wrap:break-word;
                    sb.Append("word-wrap:break-word;"); (Doesn’t work in Outlook)              
                    break;
                case "O":
                    sb.Append("overflow-wrap:break-word;"); (Doesn’t work in Outlook)                  
                    break;
                case "O2":
                    sb.Append("overflow-wrap:normal;"); (Doesn’t work in Outlook)                  
                    break;
                case "W2":
                    sb.Append("word-wrap:normal;"); (Doesn’t work in Outlook)
                    break;  
                default:
                    sb.Append("word-break:normal;");  
                    break;
            }
                
           // sb.Append("width=30;");
            sb.Append("'>");

            // http://stackoverflow.com/questions/6817262/how-to-display-html-tags-as-plain-text            
            string r;
            foreach (string row in list)
            {            
                if (isReplaceByNBSP)                  
                   r = HTML_NBSP_Convert(row);                
                else
                   r = row;
                if (isReplaceNewLine)
                    r = Regex.Replace(r, @"\r\n?|\n", "<br/>");
                sb.Append(r + "<br/>");

            }
          
            sb.Append("</body>");
            sb.Append("</HTML>");
            return sb.ToString();    
        }


tia
tina
This post has been edited by tina t: Jan 10 2020, 05:02 PM

--------------------
"the wheel never stops turning"
Go to the top of the page
 
jleach
post Jan 10 2020, 05:18 PM
Post#11


UtterAccess Administrator
Posts: 10,589
Joined: 7-December 09
From: St. Augustine, FL


Hi Tina - I'm just heading out now, but it looks like there's some code that explicitly sets this, and - generally speaking - it should be left alone unless someone really wants it:

Additionally, the constant is set to break words...

CODE
const string wordBreakFlag = "A";


CODE
          switch(workBreakFlag)
            {
                case "A":  
                    sb.Append("word-break:break-all;");  (Works in Outlook, but break up words.  Example: ‘plain’ might end up as
                                                     pl
                    ain (on next line)
                    break;
                case "W": // future: overflow-wrap:break-word;
                    sb.Append("word-wrap:break-word;"); (Doesn’t work in Outlook)              
                    break;
                case "O":
                    sb.Append("overflow-wrap:break-word;"); (Doesn’t work in Outlook)                  
                    break;
                case "O2":
                    sb.Append("overflow-wrap:normal;"); (Doesn’t work in Outlook)                  
                    break;
                case "W2":
                    sb.Append("word-wrap:normal;"); (Doesn’t work in Outlook)
                    break;  
                default:
                    sb.Append("word-break:normal;");  
                    break;
            }



I'll be back around tomorrow to take a closer look, or maybe someone else can prior to that.

Enjoy the Friday afternoon

--------------------
Jack D. Leach
Founder & CEO
Dymeng Services Inc.
Business Software Solutions
Go to the top of the page
 
jleach
post Jan 11 2020, 06:37 AM
Post#12


UtterAccess Administrator
Posts: 10,589
Joined: 7-December 09
From: St. Augustine, FL


Hi Tina - sometimes it's hard to understand why without knowing a little background, but this looks pretty straighforward...

The constant "A" is being passed to the GetHTMLBody function via the :

CODE
const string wordBreakFlag = "A";


Which in turn looks at that value to apply word break formatting (this is via the switch statement, which is the equivalent of SELECT CASE in VBA):

CODE
switch(workBreakFlag)


This is the condition that's executing:

CODE
case "A":  
                    sb.Append("word-break:break-all;");  (Works in Outlook, but break up words.  Example: ‘plain’ might end up as
                                                     pl
                    ain (on next line)
                    break;


(this seems to be the culprit)

Unless there's some specific need, I would either a) change the constant from A to a zero-length-string (or any value that doesn't exist in the switch cases, as the default case is the one you're likely wanting), or b) just don't pass that value to the GetHTMLBody method at all (it has a default of "N", which isn't in the switch case either, so the default case will be used).


--------------------
Jack D. Leach
Founder & CEO
Dymeng Services Inc.
Business Software Solutions
Go to the top of the page
 
tina t
post Jan 11 2020, 11:12 PM
Post#13



Posts: 6,693
Joined: 11-November 10
From: SoCal, USA


hi Jack, i have no idea why, lol, not knowing anything about C#, so to me it's all greek anyway. thanks for taking the time to look at it.

QUOTE
Unless there's some specific need, I would either a) change the constant from A to a zero-length-string (or any value that doesn't exist in the switch cases, as the default case is the one you're likely wanting), or b) just don't pass that value to the GetHTMLBody method at all (it has a default of "N", which isn't in the switch case either, so the default case will be used).

i'm wondering, could using the default cause the line-wrap issue to reappear? i'm only guessing that my IT guy might have added the constant declaration to address that (original) problem.

tia
tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
jleach
post Jan 12 2020, 06:08 AM
Post#14


UtterAccess Administrator
Posts: 10,589
Joined: 7-December 09
From: St. Augustine, FL


Hi - using the default adds the "word-break:normal" CSS style, which - by its name - should result in "normal" behavior.

With that said, html/CSS in emails is absolute dredges of html/CSS work, (and my own CSS skills are very elementary), so even explicitly telling it to "work normally" I wouldn't trust that it may not present some issue, paradox though it seems (I trust email styling rules about as much as I would a rabid rat).

But it should be the case that the default switch statement results in normal like break behavior.


--------------------
Jack D. Leach
Founder & CEO
Dymeng Services Inc.
Business Software Solutions
Go to the top of the page
 
FrankRuperto
post Jan 12 2020, 08:35 AM
Post#15



Posts: 1,114
Joined: 21-September 14
From: Tampa, Florida USA


Hi Tina,

Have you checked the message format settings in Outlook options?

Attached File(s)
Attached File  OutlookOptions.PNG ( 95.84K )Number of downloads: 8
 

--------------------
Currently supporting pawnbrokers that use my store management system developed with Access 2010 on Windows7. Experienced with Informix, Oracle & PostgreSQL db's.
Go to the top of the page
 
tina t
post Jan 12 2020, 11:37 AM
Post#16



Posts: 6,693
Joined: 11-November 10
From: SoCal, USA


hi Jack, and thanks for responding. i'll pass on your post to my IT guy, and cross my fingers. :) if we continue to have problems, i 'll probably be back to cry for help again... tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
tina t
post Jan 12 2020, 11:38 AM
Post#17



Posts: 6,693
Joined: 11-November 10
From: SoCal, USA


hello Frank, which setting should i be looking at? and more importantly, would these settings affect the email msg on the sending PC, or on the receiving PC?

tia
tina
This post has been edited by tina t: Jan 12 2020, 11:38 AM

--------------------
"the wheel never stops turning"
Go to the top of the page
 
FrankRuperto
post Jan 12 2020, 12:25 PM
Post#18



Posts: 1,114
Joined: 21-September 14
From: Tampa, Florida USA


Most of those settings are for outgoing. It was a shot in the dark suggestion. Is the outlook data file you are having the newline problem a PST format, or the newer OST used with O365?

You might want to look into these file format's structure: https://docs.microsoft.com/en-us/openspecs/...24-6dce75aae546

The following may not be relevant, but whenever I have scraped content from an HTML webpage and pasted it into a notepad textfile, it pasted as one long string, unless I turned on word wrap.
This post has been edited by FrankRuperto: Jan 12 2020, 12:40 PM

--------------------
Currently supporting pawnbrokers that use my store management system developed with Access 2010 on Windows7. Experienced with Informix, Oracle & PostgreSQL db's.
Go to the top of the page
 
JonSmith
post Jan 13 2020, 07:49 AM
Post#19


UtterAccess VIP
Posts: 4,073
Joined: 19-October 10



Hi,

I agree with Jack. Alot of that code seems ripped from elsewhere and not written specifically to handle this mail that is being written. Its possible its not even intended for email but for html for another purpose.
If it were my code I'd write a new function specifically for the email work or refactor it to be abstract enough to not be using CSS, as Jack indicates, using CSS formatting in your Outlook emails isnt exactly standard.
Normally Outlook will add a ton of information in the header containing formatting information that perhaps this CSS is trying to replace?
Is the formatting of this email particularly complex?

JS
Go to the top of the page
 
FrankRuperto
post Jan 13 2020, 01:26 PM
Post#20



Posts: 1,114
Joined: 21-September 14
From: Tampa, Florida USA


Hi Tina,

Why not just export the Outlook emails via automation to an Access table?.. then you can manipulate the email bodies and other Outlook fields in the Access table.

EDIT: The email bodies export to an Access Memo field as plain text.
This post has been edited by FrankRuperto: Jan 13 2020, 01:58 PM
Attached File(s)
Attached File  ExportOutlookEmails.png ( 187.62K )Number of downloads: 7
 

--------------------
Currently supporting pawnbrokers that use my store management system developed with Access 2010 on Windows7. Experienced with Informix, Oracle & PostgreSQL db's.
Go to the top of the page
 
2 Pages V  1 2 >


Custom Search


RSSSearch   Top   Lo-Fi    14th July 2020 - 06:07 PM