Page 1 of 1
Need to send HTML email with bcc, help please
Posted: Mon Sep 24, 2018 10:31 pm
by ricardo
Hi,
I need to send some HTML email to several email adress, so i will use BCC.
Can you help me pointing the best way to achieve it?
In the past i used some command line (freeware) toi achieve it.
Best Regards
Re: Need to send HTML email with bcc, help please
Posted: Tue Sep 25, 2018 12:43 am
by normeus
If your server does not require TLS then use @clipper, @ts-soft, @NALOR's code:
viewtopic.php?p=526455#p526455
You could use infratec's libcurl.pbi if you need TLS but, you'll have to make sure you follow
RFC532 to create emails. Take a look at how the
non TLS is implemented ( boundaries, content disposition, etc.. so you can see what you need to do ):
viewtopic.php?p=526583#p526583
also use google search to search for answers in purebasic forums:
https://www.google.com/advanced_search? ... rebasic.fr
Norm.
Re: Need to send HTML email with bcc, help please
Posted: Tue Sep 25, 2018 10:48 am
by loulou2522
viewtopic.php?f=14&t=35081&hilit=HTML+EMAIL
is the answering of your question.
I adapt it from Autoit, and i use it in most of my programm. It's based on CDO (object present in windows)
Hope it will help you.
Re: Need to send HTML email with bcc, help please
Posted: Tue Sep 25, 2018 11:44 am
by Dude
What's wrong with using the #PB_Mail_Bcc flag with PureBasic's "AddMailRecipient" comand? Works for me.
Re: Need to send HTML email with bcc, help please
Posted: Tue Sep 25, 2018 6:34 pm
by Sicro
Dude wrote:What's wrong with using the #PB_Mail_Bcc flag with PureBasic's "AddMailRecipient" comand? Works for me.
As far as I know, the PB-Mail-Library doesn't support HTML-formatted e-mails.
Re: Need to send HTML email with bcc, help please
Posted: Tue Sep 25, 2018 6:39 pm
by ricardo
Sicro wrote:Dude wrote:What's wrong with using the #PB_Mail_Bcc flag with PureBasic's "AddMailRecipient" comand? Works for me.
As far as I know, the PB-Mail-Library doesn't support HTML-formatted e-mails.
That is what i found.
Re: Need to send HTML email with bcc, help please
Posted: Tue Sep 25, 2018 10:10 pm
by Dude
Sorry, I overlooked the HTML bit.

Re: Need to send HTML email with bcc, help please
Posted: Thu Sep 27, 2018 2:28 pm
by swhite
Hi
I send HTML emails all the time with PB. HTML is just text so you can for example do SetMailBody(1,"<html><b>This is a test</b></html>") and it will send the email just fine and if the recipient's email client supports HTML then they see the message as expected. I can embed images in the HTML as long as I base64 encode them like so:
<img alt="Company Logo" src="data:image/jpeg;base64,**base64 encoded data goes here**">
Simon
Re: Need to send HTML email with bcc, help please
Posted: Thu Sep 27, 2018 10:24 pm
by Dude
swhite wrote:I send HTML emails all the time with PB. HTML is just text so you can for example do SetMailBody(1,"<html><b>This is a test</b></html>") and it will send the email just fine and if the recipient's email client supports HTML then they see the message as expected. I can embed images in the HTML as long as I base64 encode them like so:
<img alt="Company Logo" src="data:image/jpeg;base64,**base64 encoded data goes here**">
Thanks, Simon. I will try this when I get home.
Re: Need to send HTML email with bcc, help please
Posted: Fri Sep 28, 2018 12:01 am
by normeus
@dude, don't try it when you get home. It does not work. An email is just text but there are certain rules that have to be followed. sure you'll send html but the client will not display it, instead it will show the actual code ( gmail or outlook to name the most important ones ) here is a hack that will work on some systems like Firebird:
first create a text file with html, I called it somehtml.txt, you'll see that it is a table which makes it a single item,
as long as you use a table to insert you text it will work with gmail :
Code: Select all
<table width='100%'border=0>
<tr width='10'>
<td>nice space</td>
<td><h1><b> can this be </b> </h1></td>
<td></td>
</tr>
<tr>
<td></td>
<td style='color:red;'><h1> This hack works when <u>email reader</u> is <b>Thunderbird</b> </h1></td>
<td></td>
</tr>
<tr >
<td></td>
<td style='color:blue;'><h2>does not work?!? with <i>Outlook</i> or <i>Gmail</i></h2></td>
<td>last space</td>
</tr>
</table>
now use the PB example and make sure you use the right email and email server info, also do not add a ;SetmailBody()
Code: Select all
;
; ------------------------------------------------------------
;
; PureBasic - Mail example file
;
; (c) Fantaisie Software
;
; ------------------------------------------------------------
;
InitNetwork()
If CreateMail(0, "test@youraddress.com", "Hello last !") ;from email address
; SetMailBody(0,"<html><b>This is a test</b></html>") ; no mail Body
SetMailAttribute(0, #PB_Mail_Custom, "Content-Disposition: inline") ; if we could change the Content-Disposition from attached to inline
; it has To be an attachment no Data attachment or it wont work
;
AddMailAttachment(0, "text/html", "somehtml.txt","text/html") ; HTML
; Change the recipients to real one
;
AddMailRecipient(0, "youraddress@youraddress.com", #PB_Mail_To)
; Set the SMTP server to use
;
Result = SendMail(0, "smtp.gmail.com", 587, #PB_Mail_Asynchronous|#PB_Mail_UseSSL,"Login@gmail", "password")
Repeat
Progress = MailProgress(0)
Delay(300)
Until Progress = #PB_Mail_Finished Or Progress = #PB_Mail_Error
If Progress = #PB_Mail_Finished
MessageRequester("Information", "Mail correctly sent !")
Else
MessageRequester("Error", "Can't sent the mail !")
EndIf
EndIf
now test then Disco.
Norm.
Re: Need to send HTML email with bcc, help please
Posted: Fri Sep 28, 2018 9:43 am
by Dude
normeus wrote:@dude, don't try it when you get home. It does not work.
Correct. Simon's tip did not work for me with Gmail.

Re: Need to send HTML email with bcc, help please
Posted: Fri Sep 28, 2018 12:11 pm
by ricardo
And SSL?
Re: Need to send HTML email with bcc, help please
Posted: Fri Sep 28, 2018 4:55 pm
by swhite
Hi
My apologies for misleading everyone about sending HTML emails from PB. It turns out we are indeed using PB but the email component is based on a Chilkat email library. So I do include html in the message body but that only works because the Chilkat library correctly formats the email.
Simon
Re: Need to send HTML email with bcc, help please
Posted: Sat Sep 29, 2018 3:04 am
by Dude
@normeus, I can confirm
your trick works with Gmail and shows HTML inline for emails (see below). Nice!
Downsides: It adds an attached HTML document with the email, which is a little bit undesired but I can live with it beause I know it's necessary; but I'm mostly worried that the HTML won't show up for all mail software.
Can anyone reading this please try it with other mail apps and post their results in this topic? Thanks!
List of compatible email software: Gmail, Thunderbird.
List of incompatible email software: Mailinator.
