BBC BASIC for Windows
« Formatting email »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:13pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: Formatting email  (Read 3324 times)
Edja
Developer

member is offline

Avatar




PM


Posts: 60
xx Formatting email
« Thread started on: Apr 2nd, 2014, 2:30pm »

I'm writing a program to facilitate the organization of a tennis tournament by the end of June. One of the functionalities I need to implement is the automatic sending of roughly 1000 e-mails
Thanks to Richard's code on the WIKI :
Code:
PROCsendmailattach(SMTP$,From$,To$,"","",Subject$,ReplyTo$,Message$,Attach$) 
I managed to make this work beautifully.

In the (trivial) FN herunder I compose the message (message$) to be sent. One of the elements of this string is another string Timeslot$. Timeslot$ will be something like "Saturday 28 June 4:00 pm to 5:30 pm"

My question: Is there a way to make Timeslot$ appear in bold in the e-mails perhaps by adding some control codes ? If yes, how ?
Code:
      DEF FN_Compose_Mail
      LOCAL message$
      message$="Beste "+Voornaam1_1$+","+LF$+CRLF$+"U hebt zich ingeschreven voor ons tornooi in de "\
      \+Reeksnaam$+" punten"+LF$+CRLF$\
      \+"De wedstrijd voor de eerste ronde wordt gespeeld op"+LF$+CRLF$+"           "+Timeslot$+LF$+CRLF$\
      \+"Uw partner: "+Voornaam1_2$+"  "+Naam1_2$+LF$+CRLF$+"Uw tegenstanders:  "\
      \+Naam2_1$+"  "+Voornaam2_1$+" - "+Naam2_2$+"  "+Voornaam2_2$+LF$+CRLF$+"Mvg,"+LF$+CRLF$\
      \+"De tornooileiding"+LF$+CRLF$+"Tel: GSM 0474.449.309"+CRLF$+"Mail: info@borsbeektennisclub.be"
      =message$
 


Eddy



User IP Logged

rtr
Guest
xx Re: Formatting email
« Reply #1 on: Apr 2nd, 2014, 7:28pm »

on Apr 2nd, 2014, 2:30pm, Edja wrote:
Is there a way to make Timeslot$ appear in bold in the e-mails

A 'plain text' email is just that, I'm afraid - you don't get any kind of control over text style. To do what you want would mean sending a MIME-encoded message containing both a plain-text part (Content-Type: text/plain) and an HTML part (Content-Type: text/html); then you can use HTML tags to control formatting etc:

http://en.wikipedia.org/wiki/MIME

The receiving email client will display either the plain text part or the HTML part, depending on its capabilities and user preferences (the great majority of modern email clients can render HTML).

So what you are asking for is entirely possible, but not something that I would call 'simple'!

Richard.
User IP Logged

Edja
Developer

member is offline

Avatar




PM


Posts: 60
xx Re: Formatting email
« Reply #2 on: Apr 3rd, 2014, 08:55am »

Quote:
what you are asking for is entirely possible, but not something that I would call 'simple'!
The result, as it is, already covers the functionality. It would have been a nice touch , though.
I may revisit your solution and check the Wikipedia article in detail. If 'within my talents', I'll work on it for the next edition of the tournament in 2015.
If you say it's not that 'simple', I feel forced to give priority to the other part of the program for now.

Thank you,Richard.

Eddy
User IP Logged

rtr
Guest
xx Re: Formatting email
« Reply #3 on: Apr 3rd, 2014, 09:14am »

on Apr 3rd, 2014, 08:55am, Edja wrote:
If you say it's not that 'simple', I feel forced to give priority to the other part of the program for now.

You could cheat! Use your regular email program (not webmail) to compose a message having the format you want. Send it to yourself, and when it arrives do a 'view source'. Then you can copy-and-paste the MIME-encoded data into your BB4W program. wink

Richard.
« Last Edit: Apr 3rd, 2014, 09:20am by rtr » User IP Logged

Edja
Developer

member is offline

Avatar




PM


Posts: 60
xx Re: Formatting email
« Reply #4 on: Apr 3rd, 2014, 7:04pm »

Quote:
Use your regular email program (not webmail) to compose a message
This looks like a 'golden' cheat and I'd love to give it a try.
Unfortunately, I'm affraid I have no licence of Outlook lying around. I only use webmail. But I'll keep this in mind and see if I can try this on a friend's PC who has Outlook installed.
Perhaps next week.

Eddy
User IP Logged

rtr
Guest
xx Re: Formatting email
« Reply #5 on: Apr 4th, 2014, 09:00am »

on Apr 3rd, 2014, 7:04pm, Edja wrote:
This looks like a 'golden' cheat and I'd love to give it a try. Unfortunately, I'm affraid I have no licence of Outlook lying around.

You could always install Eudora or Thunderbird, which are free. Or, if you prefer, simply send a suitably-formatted email to me and I'll do the 'view source' and send the MIME-encoded data back to you in a ZIP.

Richard.
User IP Logged

Edja
Developer

member is offline

Avatar




PM


Posts: 60
xx Re: Formatting email
« Reply #6 on: Apr 4th, 2014, 10:49am »

Quote:
You could always install Eudora or Thunderbird, which are free
I have downloaded/installed Thunderbird and have sent an email with some text parts in bold to myself.
Then did a 'view source'. This displayed lots of data on the screen.
I 've copied/pasted this into my BB4W application and tried to apply some common sense in doing this. Several times. But,this was just trial and error and all attempts failed.
Quote:
... and send the MIME-encoded data back to you in a ZIP
I thank you for this but it seems I now got this far overhere. I'm left with 2 problems :
  • which exactly is the part that I need to copy/paste into my string Message$="...?...."
  • How do I deal with the " chars that are part of the MIME-encoded data. Do I have to replace them by "" ?
If it helps I can send you the MIME-encoded data that I've harvested in a separate mail ?

Eddy
User IP Logged

rtr
Guest
xx Re: Formatting email
« Reply #7 on: Apr 4th, 2014, 1:41pm »

on Apr 4th, 2014, 10:49am, Edja wrote:
which exactly is the part that I need to copy/paste into my string Message$="...?...."

You can't make it work that way because PROCsendmailattach() doesn't let you modify the headers. You will need to create a custom version of the procedure which, for example, has separate plain$ and html$ parameters rather than the existing body$ parameter.

The code of PROCsendmailattach() is not complicated, and as it already incorporates a MIME header to accommodate the attachment ('application/octet-stream' part) it should be straightforward to adapt it to add a new 'text/html' part.

Richard.
User IP Logged

Edja
Developer

member is offline

Avatar




PM


Posts: 60
xx Re: Formatting email
« Reply #8 on: Apr 4th, 2014, 3:31pm »

Quote:
it should be straightforward to adapt it to add a new 'text/html' part
As a famous Greek writer once said:'Beauty is in the eye of the beholder'. So is 'straightforwardness' cheesy
I'm not familiar with MIME , html and the likes and I'll have to dissect PROCsendmailattach. It will take me some time before I see clear in all this.
I have to meet the deadline for the tournament and will use PROCsendmailattach as is. The result is absolutely functional.
If some time time left I'll try to integrate this in the application otherwise after the tournament (end June)

Thank you for setting me on track.
Eddy
User IP Logged

rtr
Guest
xx Re: Formatting email
« Reply #9 on: Apr 4th, 2014, 3:54pm »

on Apr 4th, 2014, 3:31pm, Edja wrote:
As a famous Greek writer once said:'Beauty is in the eye of the beholder'. So is 'straightforwardness' cheesy

You yourself used the word 'trivial' without qualification! In fact, looking again at the procedures, whilst it's correct that you cannot do what you want using the unmodified PROCsendmail() you can using PROCsendmailattach() because it's already got the necessary MIME ingredients. So it's even easier than I thought!

Quote:
I have to meet the deadline for the tournament and will use PROCsendmailattach as is. The result is absolutely functional.

Seems a shame when what you would have liked to achieve could be done in minutes. In fact my suspicion is that the only reason what you tried before didn't work was that you didn't appreciate that you needed to change the 'boundary string' from whatever Thunderbird used to "--BB4Wsep" which is what PROCsendemailattach uses.

Richard.
User IP Logged

rtr
Guest
xx Re: Formatting email
« Reply #10 on: Apr 4th, 2014, 4:28pm »

on Apr 4th, 2014, 3:54pm, Richard Russell wrote:
Seems a shame when what you would have liked to achieve could be done in minutes.

I've sent you an email that is, I believe, the best that can be done using the unmodified PROCsendmailattach(). As you will see it's not perfect because there's a spurious 'attachment' containing a copy of the HTML, which you would probably prefer isn't there. To eliminate that would need a small change to the procedure.

Edit: Here's the modified procedure:

http://bb4w.wikispaces.com/Sending+an+HTML+email+with+optional+attachments

Richard.
« Last Edit: Apr 4th, 2014, 5:06pm by rtr » User IP Logged

Edja
Developer

member is offline

Avatar




PM


Posts: 60
xx Re: Formatting email
« Reply #11 on: Apr 4th, 2014, 7:04pm »

It worked !
Thanks to Richards adapted PROCsendmailhtmlattach(smtp$,from$,rcpt$,cc$,bcc$,subject$,replyto$,plain$,html$,attach$)

I've sent the simplest possible email to myself with just one word in bold to avoid obscuring the issue. Once the email is received the result is like this :
Quote:
Beste,

dit is de tekst voor de test

Eddy

As an example for those (like me) who are not familiar with MIME, htlm,... it's maybe useful to show the 2 functions that create the plain text and the html text .
This 'cheat' will allow you to create some effects inside the emails. I only tested out bold text for now, but will play around with other format effects. Pls. read the previous posts from Richard in this thread where is explained how to get the relevant parts out of, in this case, Thunderbird
And don't forget to replace " with "" in the body text
Code:
     DEF FN_Compose_Plain
      Plain$="Beste,"+CRLF$+\
      \"dit is de*tekst *voor de test"+CRLF$+\
      \"Eddy"
      = Plain$
      REM----------------------------------------------------------
      DEF FN_Compose_Html
      Html$="<body text=""#000000"" bgcolor=""#FFFFFF"">"+CRLF$+\
      \"Beste,<br>"+CRLF$+\
      \"<br>"+CRLF$+\
      \"dit is de<b> tekst </b>voor de test<br>"+CRLF$+\
      \"<br>"+CRLF$+\
      \"Eddy<br>"+CRLF$+\
      \"</body>"
      =Html$ 

Eddy
User IP Logged

rtr
Guest
xx Re: Formatting email
« Reply #12 on: Apr 4th, 2014, 8:03pm »

on Apr 4th, 2014, 7:04pm, Edja wrote:
It worked !

I'm slightly surprised, since your HTML appears to have no <html></html> tags. Is there some specific reason why you didn't use my example code on the Wiki as a template?

Code:
      Plain$   = "This is a test of sending an HTML email."
      HTML$    = "<html><head></head><body>" + \
      \          "This is a test of sending an <b><i>HTML</i></b> email." + \
      \          "</body></html>" 

You may feel that I should have added those tags in PROCsendmailhtmlattach(), and that might have been sensible, but I didn't!

Richard.
User IP Logged

Edja
Developer

member is offline

Avatar




PM


Posts: 60
xx Re: Formatting email
« Reply #13 on: Apr 4th, 2014, 10:00pm »

Quote:
your HTML appears to have no <html></html> tags. Is there some specific reason why
No specific reason. It just seemed the 'natural' way to proceed. I assumed the tags would be provided by PROCsendmailhtmlattach().

I admit that I was so eager to try it out that I overlooked the part of the WIKI article with the example code. I just copied the updated procedure and then coded the two functions FN_Compose_Plain and FN_Compose_Html.
Once it worked and after reporting back here on the forum I read the article again and discovered that I deviated from your example code. In the mean time I already modified the two functions and added the <html></html> tags

If it wouldn't have worked I would have looked at the article sooner to find out what was wrong and I would have seen the missing tags. But since my code also works without the tags, I now wonder if they are really required

Eddy
User IP Logged

rtr
Guest
xx Re: Formatting email
« Reply #14 on: Apr 4th, 2014, 10:37pm »

on Apr 4th, 2014, 10:00pm, Edja wrote:
But since my code also works without the tags, I now wonder if they are really required

So you've tried it with every email client that your recipients might be using? You have been busy! wink

Please forgive the sarcasm, but I'm sure you appreciate that 'trial and error' coding is no more acceptable in HTML than it is in BBC BASIC (indeed probably less so, because there's a greater variety of email clients and HTML rendering engines than BBC BASIC interpreters!).

The only certain way of determining whether the tags are required is to refer to the relevant RFC(s), but I think one can assume that if Thunderbird (for example) includes them then they are at least desirable.

Richard.
User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls