Need to send HTML email with bcc, help please

Just starting out? Need help? Post your questions and find answers here.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Need to send HTML email with bcc, help please

Post 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
ARGENTINA WORLD CHAMPION
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Need to send HTML email with bcc, help please

Post 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.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
loulou2522
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Oct 14, 2014 12:09 pm

Re: Need to send HTML email with bcc, help please

Post 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.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Need to send HTML email with bcc, help please

Post by Dude »

What's wrong with using the #PB_Mail_Bcc flag with PureBasic's "AddMailRecipient" comand? Works for me.
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 559
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Need to send HTML email with bcc, help please

Post 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.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Need to send HTML email with bcc, help please

Post 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.
ARGENTINA WORLD CHAMPION
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Need to send HTML email with bcc, help please

Post by Dude »

Sorry, I overlooked the HTML bit. :oops:
swhite
Enthusiast
Enthusiast
Posts: 789
Joined: Thu May 21, 2009 6:56 pm

Re: Need to send HTML email with bcc, help please

Post 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
Simon White
dCipher Computing
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Need to send HTML email with bcc, help please

Post 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.
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Need to send HTML email with bcc, help please

Post 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.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Need to send HTML email with bcc, help please

Post 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. :(
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Need to send HTML email with bcc, help please

Post by ricardo »

And SSL?
ARGENTINA WORLD CHAMPION
swhite
Enthusiast
Enthusiast
Posts: 789
Joined: Thu May 21, 2009 6:56 pm

Re: Need to send HTML email with bcc, help please

Post 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
Simon White
dCipher Computing
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Need to send HTML email with bcc, help please

Post 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.

Image
Post Reply