Sending Mail

Moderator: Rathinagiri

User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Sending Mail

Post by Roberto Lopez »

Hi All,

I'm developing an utility that sits on system tray and once a day (at specific time) checks the content of a MySql table.

Depending of the content of the table, I must to send an email warning to certain customers.

The mail account to be used is a Gmail one.

So, the question is, which is currently the best method to send a mail using a Gmail account from an HMG app (is preferable that not mail client be required).

TIA.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Sending Mail

Post by esgici »

Roberto Lopez wrote:Hi All,

I'm developing an utility that sits on system tray and once a day (at specific time) checks the content of a MySql table.

Depending of the content of the table, I must to send an email warning to certain customers.

The mail account to be used is a Gmail one.

So, the question is, which is currently the best method to send a mail using a Gmail account from an HMG app (is preferable that not mail client be required).

TIA.
Field expert is Daniel Maximilian,

I hope he will come soon ...

Best regards
Viva INTERNATIONAL HMG :D
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Sending Mail

Post by mol »

I've implemented CDO (pattern from our forum). It works OK, one of my clients sends hundreds of mails with attachments everyday.
Thanks.

Does it requires that an email client be installed to make it work?
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Sending Mail

Post by Roberto Lopez »

Marek,

By mistake, I've edited your post instead of reply it (I've confused the buttons).

I'm very sorry for that (is early in the morning here and I've not drink my cofee yet :).

Could be you so kind to post the code again?

Thanks.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
gfilatov
Posts: 1067
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Sending Mail

Post by gfilatov »

Hi Roberto,

Harbour have now an own e-mail support with SSL via the function hb_SendMail().
There is a sample of usage in the file harbour\contrib\hbtip\tests\gmail.prg.
Also is important that you should installed the OpenSSL on your computer.

Code sample:

Code: Select all

hb_SendMail( ; 
"smtp.gmail.com", ; 
465, ; 
cFrom, ; 
cTo, ; 
NIL /* CC */, ; 
{} /* BCC */, ; 
"Test message", ; 
"Test subject", ; 
{"gmail.prg"} /* attachment */, ; 
cFrom, ; 
cPassword, ; 
"", ; 
NIL /* nPriority */, ; 
NIL /* lRead */, ; 
.T. /* lTrace */, ; 
.F., ; 
NIL /* lNoAuth */, ; 
NIL /* nTimeOut */, ; 
NIL /* cReplyTo */, ; 
.T., ; 
NIL /* cSMTPPass */, ; 
"es-ar" )
Hope that useful.
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
EduardoLuis
Posts: 682
Joined: Tue Jun 04, 2013 6:33 pm
Location: Argentina

Re: Sending Mail

Post by EduardoLuis »

Hi Roberto:

Here i attach CDOSYS mail (i think is last version Daniel Maximiliano creates).-
I don't test it, so i don't know how it works.-
Hope this helps you.-

Mol also develope a good send mail system.- I'll look where i've put it, and upload then.-

Please tell us if it woks.-
With regards.
Eduardo
Attachments
MAIL_SEND_D_MAXIMILIANO.zip
(1.55 MiB) Downloaded 376 times
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Sending Mail

Post by mol »

my working code based on Daniel example:

Code: Select all

BEGIN SEQUENCE WITH {|e| break(e)}
   
		oCfg := CREATEOBJECT( "CDO.Configuration" )
		WITH OBJECT oCfg:Fields
			:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" )      :Value := cSystemowySMTPServer
			:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" )  :Value := nSystemowySMTPPort
			:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" )       :Value := 2
			:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := .T.
			:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" )      :Value := lSystemowySMTPSSL
			:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") :Value := 1
			:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" )    :Value := cSystemowySMTPUser
			:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" )    :Value := cSystemowySMTPPassword
			:Update()
		END WITH

		oMsg := CREATEOBJECT ( "CDO.Message" )
		
		WITH OBJECT oMsg
			:Configuration := oCfg
			:BodyPart:Charset := "windows-1250"
			//:BodyPart:Charset := "utf-8"
			//:From          := hb_strtoutf8(OknoWyslijWiadomosc.T_ODKogo.Value,"PLWIN")
			:From          := alltrim(OknoWyslijWiadomosc.T_ODKogo.Value)
			:To            := alltrim(OknoWyslijWiadomosc.T_DO.Value)
			:CC            := alltrim(OknoWyslijWiadomosc.T_DW.Value)
			:Subject       := alltrim(OknoWyslijWiadomosc.T_Temat.Value)
			:TextBody      := rtrim(OknoWyslijWiadomosc.T_Tresc.Value) + e"\r\n"
			
			//TODO: To send HTML body, uncomment the following lines:
			//String cHtml;
			//cHtml := "<HTML>\n"                                     + ;
			//	"<HEAD>\n"                                            + ;
			//	"<TITLE>Sample GIF</TITLE>\n"                         + ;
			//	"</HEAD>\n"                                           + ;
			//	"<BODY><P>\n"                                         + ;
			//	"<h1><Font Color=Green>Inline graphics</Font></h1>\n" + ;
			//	"</BODY>\n" + ;
			//	"</HTML>" 
			//:TextBody := cHtml 

			//TODO: To send WEb page in an e-mail, uncomment the following lines and make changes in TODO section.
			//TODO: Replace with your preferred Web page
			//:CreateMHTMLBody("http://www.microsoft.com",
			//	CDO.CdoMHTMLFlags.cdoSuppressNone, 
			//	"", "")
			// :Subject = "Test SMTP";  

			for i:=1 to len(aZalaczniki)
				:AddAttachment(aZalaczniki[i])
			next i

			:Send()
		ENDWITH
	RECOVER USING e
		MsgStop ( "Nie udało się wysłać wiadomości z powodu:"                        + Chr(13) + Chr(10) + ;
                "opis błędu: "   + e:Description +chr(10)+;
				"sprawdź ustawienia konta pocztowego lub zabezpieczenia, np. firewall")
                //"Error: "     + TRANSFORM(e:GenCode   , NIL)   + Chr(13) + Chr(10) + ;
                //"SubC: "      + TRANSFORM(e:SubCode   , NIL)   + Chr(13) + Chr(10) + ;
                //"OSCode: "    + TRANSFORM(e:OsCode    , NIL)   + Chr(13) + Chr(10) + ;
                //"SubSystem: " + TRANSFORM(e:SubSystem , NIL)   + Chr(13) + Chr(10) + ;
		Wait Clear
		Return 
	END
   
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Sending Mail

Post by Roberto Lopez »

Marek,

Thanks for all the info about this.

I've successfully made work hb_sendmail() with a gmail account.

My goal is always to make my apps portable, not requiring another things installed. This is the reason to avoid solutions involving mail clients.

In this case, is not necessary to install SSL on the destination machine. Copying, the required dlls (only two) to the app folder, is enough to make it work.

Thanks Again!
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Sending Mail

Post by Roberto Lopez »

EduardoLuis wrote:Here i attach CDOSYS mail (i think is last version Daniel Maximiliano creates).-
I don't test it, so i don't know how it works.-
Hope this helps you.-
I've finally decided to use hb_sendmail() because it worked fine in the first attempt and I must to complete the app for tomorrow (no time for experimentation :) )

I'll make more experimentation when have some available time. I'll look for CDO for next developments.

Thanks!
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Sending Mail

Post by Roberto Lopez »

gfilatov wrote:Harbour have now an own e-mail support with SSL via the function hb_SendMail().
There is a sample of usage in the file harbour\contrib\hbtip\tests\gmail.prg.
Also is important that you should installed the OpenSSL on your computer.
Grigory:

It worked like a charm in the first attempt.

As I've explained to Marek, is not required to install SSL in the destination machine.

Copying some of the dlls to the app folder is enough to make it work.

Thanks Again!
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
Post Reply