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 13 2020, 01:46 PM
Post#21



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


hello, guys, and thanks all for responding. :)

QUOTE
Is the formatting of this email particularly complex?

no it isn't, Jon. the body is a simple text string, which includes one carriage return/line feed. i provide the text string via a query in Access; it's just concatenated fields and strings of spaces. if i were generating the emails myself, i wouldn't use HTML (or CSS, which i know nothing at all about).

EmailRecord: IIf([feXXX]=0,"",[feXXX] & " " & [feXXXXXXXX] & " ") & Left([feXXXX] & " ",11) & [feXXXXX] & " " & [feXX] & IIf(Len([feXXXXXXXX] & "")=0,""," " & IIf([feXXXXXXXX]="YYY"," ",Left([feXXXXXXXXXX] & (" "+[feXXXXXXXXXX]) & " ",18))) & " " & [feXXXXXX] & IIf(Len([feXXXXXXX] & "")=0,""," " & Chr(13) & Chr(10) & [feXXXXXXX])

it's not pretty, but it works as needed. the query never returns more than 2-3 records at each run, so no speed issues. the output looks like

1234-567 1234-56 123456 XXX
THIS IS JUST A TEST. LET'S SEE HOW THE NOTES LOOK IN AN EMAIL. GOOD, I HOPE - BECAUSE IT MEANS MY IT GUY DOESN'T HAVE TO MAKE ANY MORE CHANGES TO HIS CODE.

seriously, that's it. the original issue was that there was no CRLF in the text, and no line wrap, the line just went off the right side of the window. then my IT guy got the CRLF to "take", and got the line wrap sorted out. all good, except the line breaks anywhere within a word or between a word and immediately following punctuation, instead of moving a whole word(+punctuation) down to the next line.

tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
FrankRuperto
post Jan 13 2020, 02:01 PM
Post#22



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


Tina,

QUOTE
except the line breaks anywhere within a word or between a word and immediately following punctuation, instead of moving a whole word(+punctuation) down to the next line.


So then you dont have word wrap totally figured out. Why not export the email bodies as plain text to an Access table, as I mentioned in my previous post?

--------------------
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, 04:58 PM
Post#23


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



So my guess is your IT guy tried to mix and match code to fudge a solution and he found something out of context on StackOverflow that showed him how to use CRLF in html then pushed that into an email.
Its really really not the way to do it.

Can you ask him to just push it through, as HTML but you give him the string formatted already? Its not great abstraction but will make you less dependent on this less than reliable IT guy.

For 'normal' html all you need to do is wrap that line in <Div> </Div> tags similar to how we format our quote tags here on UA and when you need a line break rather than CRLF insert a </BR>
Go to the top of the page
 
tina t
post Jan 13 2020, 09:33 PM
Post#24



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


hi Frank, thanks for responding. sorry, hon, i don't see the advantage to adding a table as an intermediate step in generating the emails. what difference will it make for the C# program to read data from a table's recordset as opposed to a query's recordset? help?

tia
tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
tina t
post Jan 13 2020, 09:49 PM
Post#25



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


QUOTE
For 'normal' html all you need to do is wrap that line in <Div> </Div> tags similar to how we format our quote tags here on UA and when you need a line break rather than CRLF insert a </BR>

hi Jon, thanks for responding. would the calculated field in the query then look like

EmailRecord: "<Div>" & IIf([feXXX]=0,"",[feXXX] & " " & [feXXXXXXXX] & " ") & Left([feXXXX] & " ",11) & [feXXXXX] & " " & [feXX] & IIf(Len([feXXXXXXXX] & "")=0,""," " & IIf([feXXXXXXXX]="YYY"," ",Left([feXXXXXXXXXX] & (" "+[feXXXXXXXXXX]) & " ",18))) & " " & [feXXXXXX] & IIf(Len([feXXXXXXX] & "")=0,""," </BR>" & [feXXXXXXX]) & "</Div>"

instead of the current

EmailRecord: IIf([feXXX]=0,"",[feXXX] & " " & [feXXXXXXXX] & " ") & Left([feXXXX] & " ",11) & [feXXXXX] & " " & [feXX] & IIf(Len([feXXXXXXXX] & "")=0,""," " & IIf([feXXXXXXXX]="YYY"," ",Left([feXXXXXXXXXX] & (" "+[feXXXXXXXXXX]) & " ",18))) & " " & [feXXXXXX] & IIf(Len([feXXXXXXX] & "")=0,""," " & Chr(13) & Chr(10) & [feXXXXXXX])

so the query output for the field would be the following text, as

<Div>1234-567 1234-56 123456 XXX</BR>THIS IS JUST A TEST. LET'S SEE HOW THE NOTES LOOK IN AN EMAIL. GOOD, I HOPE - BECAUSE IT MEANS MY IT GUY DOESN'T HAVE TO MAKE ANY MORE CHANGES TO HIS CODE.</Div>

or am i missing the boat? sorry if i'm asking stupid questions, but i really don't know anything about this. i appreciate your patience!

tia
tina

btw, i will say in my IT guy's defense that he's generating other emails for me that don't have long enough lines for linewrap to be an issue, and they all work fine. plus he wrote a program for me to use in issuing material certifications for our customers (i'm a clerk here, not IT), and it is truly excellent - miles better than the program that i'd been using for the past 13+ years. all in C#. :)

--------------------
"the wheel never stops turning"
Go to the top of the page
 
FrankRuperto
post Jan 13 2020, 11:14 PM
Post#26



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


Hi Tina,

I think converting the data to plain text would be a lot more manageable for C# or any other target language to deal with versus using that ungodly looking vba hack for massaging the email body strings that doesnt seem to be 100% reliable.If another tool like the Outlook export wizard accomplishes conversion to plain text, so be it. Why spend extra time re-inventing the wheel? Maybe there's a C# function out there for converting html strings to plain text that can also solve your problem.
This post has been edited by FrankRuperto: Jan 13 2020, 11:21 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
 
jleach
post Jan 14 2020, 05:19 AM
Post#27


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


>> or am i missing the boat? <<

No, that's the right direction.

Realize that different environments have different qualifiers used to render a line break. While in Access, VBA, text files and a number of other places CRLF is indeed the desired character (or pair of characters) to implement a line break, in HTML this has no meaning (except in very specific circumstances). The HTML equivalent to CRLF is the <br /> tag (JavaScript has a different one, other languages/environments vary a bit as well).

Wrapping the whole thing in a set of <div></div> tags basically says "treat this as an entire block of output" and is a good default practice. There's other ways to force line breaks also... but this <br /> tag should be sufficient in this case.

So "div" says "here's a block of text" and "br" says "here's some line breaks within that block of text"


That said, there's still potentially the issue of that switch statement... even with explicit HTML-version line breaks (br instead of crlf), you'll still want the "normal" CSS switch case, otherwise you'll wind up with both your line breaks via the br tags as well as breaking on words if the line is too long.


(like Jon, I tend to feel that the C# methods being used are somewhat hacked together and unclean and were it up to me, I'd just take the 15 minutes and refactor it, but that'd be hard to do in the forum here with a middle(wo)man to boot)

Anyway, use the div, br and make sure the switch statement is running the default branch to set the CSS word-break to normal, and you should be good to go.

hth

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



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


QUOTE
I think converting the data to plain text would be a lot more manageable for C# or any other target language to deal with versus using that ungodly looking vba hack for massaging the email body strings that doesnt seem to be 100% reliable.

hi Frank, thanks for responding. sorry, i don't understand your reference to converting the data to plain text, and a vba hack. the query output that the C# code uses is plain text - hmm, except for the Chr(13) & Chr(10), which works - and there's no VBA involved with any of this, unless you're referring to the Access built-in functions IIf(), Left() and Len(). and as i said, the C# program doesn't work with the concatenation; it works with the query output, which is simple text.

tina

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



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


QUOTE
Anyway, use the div, br and make sure the switch statement is running the default branch to set the CSS word-break to normal, and you should be good to go.

hello Jack, and thanks for responding. yes, i know that using a go-between (especially one who is clueless about the subject) is not conducive to resolving the problem. i really appreciate your - and Jon's - patience with the situation and me. i'll revamp my query to output the string with the changes, and ask my IT guy to give it a run with the switch statement returning the default normal, and we'll see what happens. :)

tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
JonSmith
post Jan 15 2020, 07:23 AM
Post#30


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



Great you fully understood my suggestion and could implement it!

When you want to test out any HTML you might generate a great site for it is
https://www.w3schools.com/hTML/tryit.asp?fi...e=tryhtml_intro

If you paste in the html you wrote you can see what the expected output is. To me it looks correct smile.gif
Go to the top of the page
 
jleach
post Jan 15 2020, 07:59 AM
Post#31


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


Ha, know what? I just realized you can completely override the IT person's line break settings by supplying your own in the div tag...

Instead of starting with "<div>..." start it with "<div style='word-break:normal;'>..." (watch the quotes... single or double work fine in html, but make sure they're delimited correctly)

The styling your IT person is doing is at a higher level, and CSS is cascading (Cascading Style Sheets), so by putting the word-break directive lower in the tree, at the div that surrounds your code, it'll override whatever your IT person has higher up in the tree where that code is doing it.

Granted, it's probably a better practice to not force the format this way (it's "cleaner" to let it happen via the C# code), but that'd work as well.

The query output should be something like:

CODE
<div style='word-break:normal;'>Your Text Line One<br />Your Text Line Two<br/>Your Text Line Three</div>


(that's why a div is helpful... it treats everything within as a single unit, so to speak, and you can then apply styles to that unit)

Anyway, should have thought of that earlier (being able to override global styles is one of the core aspects of CSS - thus Cascading).

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



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


hello Jon, thanks for the link, hon - that is so cool! :) thanks for the encouragement and for sticking with me! tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
tina t
post Jan 15 2020, 02:49 PM
Post#33



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


QUOTE
Instead of starting with "<div>..." start it with "<div style='word-break:normal;'>..." (watch the quotes... single or double work fine in html, but make sure they're delimited correctly)

hello Jack, and thanks! i'm going to change the query expression right now and test it. i can do that without bothering IT because this is a working setup (for nearly 4 years, it's just the addition of the "note" that is new, and causing the headaches) and the email-generating program runs automatically every few minutes. i'll post back and let you and Jon know how it goes. :) tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
tina t
post Jan 15 2020, 09:14 PM
Post#34



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


hi Jack and Jon, unfortunately, it didn't work at all. :(

this is what the email body shows, literally, in a test email that the program sent to me:

<div style='word-break:normal;'>XXXX-XXX XXXX-XX 999999 XXX <br/>THIS IS JUST A TEST. LET'S SEE HOW THE MGR NOTES LOOK IN AN EMAIL. GOOD, I HOPE - BECAUSE IT MEANS MY IT GUY DOESN'T HAVE TO MAKE ANY CHANGES TO HIS CODE.</div>

and no line break, and no line wrap, trailing off the right side... back to square one.

<sigh> i'm strongly considering just writing some code in VBA to send the email, calling the code from an AutoExec macro, and asking IT if they can just open the db every x minutes and then close it again. i just don't understand how this can be so hard, when i have some emails that i send via VBA without any HTML, and one or two where i do use HTML but the tags (?) are just included in the string value i assign to the body property of the email.

anyway, thanks very much for all your time and help, guys. i did learn a little bit, and that's never a bad thing. :) tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
FrankRuperto
post Jan 16 2020, 12:39 AM
Post#35



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


Reviewing your IT guy's code, are those the correct regular expresions for replacing newline and wordwrap?
I also dont see any metion of wordwrap in the case statement. Is that just for the header part?
How was the IT guy sending out emails before via a C# program?

CODE
// 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/>");

            }

This post has been edited by FrankRuperto: Jan 16 2020, 12:42 AM

--------------------
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 16 2020, 05:52 AM
Post#36


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



Thats super strange Tina, the email is either being converted to plain text or the IT guy has code that is ensuring that those HTML tags get transformed into plain text.

Its a real shame he's making this your issue. As Jack and I suggested, his code is a hack job. Do you have any lee-way to push back and get someone to do his code properly?

JS
Go to the top of the page
 
jleach
post Jan 16 2020, 06:39 AM
Post#37


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


Yea, it's a bit baffling. I'd be interested to walk through the full code in a debug session... (feel free to email/PM me if you'd like me to do so)

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



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


Strange indeed, I would guess the text would need to be parsed and need code to handle start, end and simple tags, and append a newline character where needed.

I found this link, it might help: https://stackoverflow.com/questions/286813/...l-to-plain-text
This post has been edited by FrankRuperto: Jan 16 2020, 09:28 AM

--------------------
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 16 2020, 01:50 PM
Post#39



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


hello Jon, we're a fairly small company, very small IT dept, and just this one guy who knows C# well. and, as i mentioned before, he has done excellent work in C# apps fronting Access BE dbs - and other sources including SQL Server - for me and for other depts too. i'm guessing that in C#, as in Access, you learn what you need. i know i do, and can be a complete newbie on something i haven't faced before. i remember the criticism i got some years ago when i posted for help with VBA code that inserts data into existing Excel files; i had cobbled together code i gleaned from internet sites and from Help, and apparently hadn't done a very good job...

hello Jack, thanks for your offer, i'll PM you shortly. :)

hello Frank, thanks for the link!

i appreciate your continuing interest and time, guys, you're the best! :) tina

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



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


okay, guys, looks like we're at a deadend with this issue. i'll say again how much i appreciate everyone's time and efforts to help me get the problem corrected. i'll try my VBA alternative, or just live with a somewhat-poor-quality email going out. but, regardless, that's at my end. at your end, a huge THANK YOU! and an A+. :) tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
2 Pages V < 1 2


Custom Search


RSSSearch   Top   Lo-Fi    5th July 2020 - 05:44 AM