B4J Question How to get text aligned in form of a table when transferring the text to a email?

BlueVision

Active Member
Licensed User
Longtime User
Hi folks,
I am working on a software where it is necessary to send small plain text emails within the company network. The content of these emails must necessarily appear in table-like form in the email. This has been explained several times in other places here in the forum, the case here is a little more special.
As far as I know, you can send emails in B4J (it is a B4J application) in two ways:

1. you send the email via SMTP and then you can design the content of the email quite freely (HTML etc.)
2. you generate the email via JFX and send the email content to the email programme on your PC

Of course, I would prefer the first option, but unfortunately direct access to the SMTP server in the company network is blocked for security reasons. Sending via SMTP therefore does not work. Using an external email address (another SMTP server) works, but occasionally emails end up in the recipient's spam folder and this approach is generally not appreciated by the company's IT department. These are primarily security-related hurdles that unfortunately preclude sending via SMTP.

When using the second variant, there are no security problems, but formatting the email content is very difficult.
The client uses Outlook and via the well-known JFX function I can also transfer the desired text to Outlook and open the email window. The problem with this variant is the flexible length of the characters of a font in Outlook itself. These then naturally lead to lateral shifts within the text of the email.
Unfortunately, tab functions do not work with this variant either. Tabs are generated, but consist of 2 or 4 spaces, depending on the definition in Outlook, which unfortunately does not change the problem of the shifts.

The first solution would be to somehow get Outlook to generate the email with a monospace font, which would then immediately eliminate the shifts in the table. But how?

A second solution could be measuring the text length of the texts in the individual columns and to artificially lengthen the corresponding string in order to generate an alignment in the form of a table again. Or even better: The string passed for the email body itself takes care of the corresponding setting in Outlook, perhaps even for the display in HTML form. Unfortunately, my attempts to pass even a simple HTML string to Outlook in this way failed. Perhaps there is a solution for this?
Or is the use of Textmetric possibly a solution?

Any comments are really welcome...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
1st:
The GMail-Option is not really an alternative because of the security restrictions of the company, it is the same as with SMTP from a different external mailserver (which works, but gets no acceptance by the company IT)

2nd:
B4X:
    Dim FX As JFX
    Dim MailAdress As String = "[email protected]; [email protected]"
    Dim MailSubject As String = "Meldung%20eines%20neuen%20Modells"
    Dim MailBody As String
    MailBody = "Gemeldet von:%09%09" & LUser.Text    & "%0D%0A"
    If XCBArea.SelectedIndex = 1 Then MailBody = MailBody &"Servicegebiet:%09%09RDE 10 - Hamburg%0D%0A"
    MailBody = MailBody & "Neues%20Modell:%09%09" & TFDescription.Text & "%0D%0A" & "Seriennummer:%09%09" & TFSerial.Text
    FX.ShowExternalDocument("mailto:" & MailAdress & "?subject=" & MailSubject & "&body=" & MailBody)

This (simplified) code opens outlook and fills the fields correctly.
The formatting of the email body, however, becomes a problem because of the font used by outlook. Yes, you can change it, but how will 400 force people to change the default font in outlook just because of that?

This output is generated by default, Outlook is using Calibri as Default Font

Unbenannt1.jpg

When switching to a monospaced font (Lucida Console) the formatting is correct.

Unbenannt2.jpg


Imagine what an order list with several "columns" would look like now? Due to the use of proportional fonts, the shifts worsen the more columns are included in the table-like display.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
I had been dreading this answer.... But you are right Erel, this procedure is very limited, but due to the restrictions of the company IT, I unfortunately have to go this way.
Your suggestion looks promising, but I'm afraid that even this approach will most likely be rejected by the corporate IT. They are very restrictive and make the rules.

But another approach would be to analyse the width of individual letters and determine a theoretical value for the width. Depending on this value, one could then add more "spaces". A look at the character table for the font "Calibri", for example, shows the character "U+200A" (minimum space). This should be a space with a width of 1-2 pixels. The rest is then a DoWhile loop in which this character is appended to the existing string until it is filled to the maximum size.
It's not elegant by any means, but I also just don't see any way to straighten out the typeface in any way. This should be easy in the example above, as the front part of the string (before the ":") does not change. In this case, I get further with simple trial and error.
It gets more complicated later when other emails with 4-5 "columns" are generated and the shifts add up. Basically, I have to try to generate a working tabulator algorithm in some way.

Thanks for the time you spent Erel, sometimes you lose. Merry Christmas to you and your family!
 
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
Well, I must grant to send an text-only email from one employee to another within the company network. Simple plain text.
- Direct call of the SMTP- and IMAP-Server is blocked for security reasons by the company IT.
- Mailings from "outside" could end in SPAM
- It should only open a prefilled mail in outlook automatically. Sending should be done by the employee by pressing the send-button in outlook.

So there is only a chance to do it with the default email program. This is outlook (what else :mad:).
So the goal is to put the text in the mailbody with all this restrictions somehow aligned in columns by filling up with small spaces or outlook force to use a monospace-font.

Mates, it is christmas.
Please only deal with the problem if you really want to find a solution. Now is the time for family and friends.
However, I would be very grateful if someone could come up with a workaround for the problem, even if it is not very elegant and primitive. It doesn't matter, it has to work.
The easiest thing would really be to force Outlook to switch to a font like "Lucida Console" for this one mail. Then all the problems would be solved in one fell swoop. It is just annoying to have to deal with such a problem and not be able to continue working on the actual code of the programme.

Again, merry christmas to all of you.
 
Upvote 0
Top