FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour send mail
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
send mail
Posted: Wed May 20, 2015 07:26 PM

Someone have a easy function to send a message ( also html) from fwh . thanks

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: send mail
Posted: Thu May 21, 2015 12:51 AM
This is what I use.
Code (fw): Select all Collapse
*-------------------------------------------------------------------------------------------------------------------------------*
Function SendMail( oDlg, cSender, cPass, cDisplay, cReply, lSave, cTo, cCC, cSubject, cMsg, lReceipt, cAttach, lMsgInfo )
*-------------------------------------------------------------------------------------------------------------------------------*
Local oEmailCfg,oEmailMsg,oError,cHtml, cLine, n
local nSuccess 

nSuccess := 1

Default lReceipt := .T., lMsgInfo := .F., lSave := .T., cAttach := '', cSubject := '', cDisplay := MEMVAR->coname, cMsg := '', cCC := '', ;
          cReply := cSender, cGstNo := ''

cMsg := alltrim(cMsg)

CursorWait()

cHtml:='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'
cHtml+='<HTML><HEAD>'
cHtml+='<META content="text/html; charset=windows-874" http-equiv=Content-Type>'
cHtml+='<META name=GENERATOR content="MSHTML 8.00.6001.18783">'
cHtml+='<STYLE></STYLE>'
cHtml+='</HEAD>'
cHtml+='<BODY bgColor=#ffffff>'
cHtml+='<DIV>'

// cHtml += '<DIV><FONT size=2 color=blue face=Arial>Hello How are you ?</FONT></DIV></BODY></HTML>'

cHtml += cMsg
cHtml += '</DIV></BODY></HTML>'

TRY
  oEmailCfg := CREATEOBJECT( "CDO.Configuration" )
  WITH OBJECT oEmailCfg:Fields
     :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value                 := "smtp.gmail.com"
     :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value         := 465
     :Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value              := 2   // Remote SMTP = 2, local = 1
     :Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value       := .T.
     :Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value                 := .T.
     :Item( "http://schemas.microsoft.com/cdo/configuration/savesentitems" ):Value          := lSave
     :Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value           := cSender  //  "email@gmail.com"
     :Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value           := cPass // Password
     :Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 60
     :Update()
  END WITH

CATCH oError

    if lMsgInfo
        MsgAlert("Could not send message" +CRLF+  ;
            "Error: " + TRANSFORM(oError:GenCode, NIL) +CRLF+  ;
            "SubC: " + TRANSFORM(oError:SubCode, NIL) +CRLF+  ;
                "OSCode: " + TRANSFORM(oError:OsCode, NIL) +CRLF+  ;
                "SubSystem: " + TRANSFORM(oError:SubSystem, NIL) +CRLF+  ;
                "Message: " + oError:Description )
    else
    nSuccess := 0
    end
END
oError:=NIL

TRY
    oEmailMsg := CREATEOBJECT ( "CDO.Message" )
    WITH OBJECT oEmailMsg
        :Configuration  := oEmailCfg
        :From               := chr(34)+cDisplay+" "+chr(34)+ "<"+cReply+">" // cSender  // This will be displayed in the From (The email id does not appear)
        :To                 := cTo   // "dutch@easyfo.com"    // <-----   Place your email address
        :Subject            := cSubject  //   "Email Test Message from GMail"
        :ReplyTo            := cReply
        :MDNRequested   := .F.
        if !empty(cAttach)
              :AddAttachment(cAttach)
        end
        :HTMLBody = cHtml
    END WITH
    oEmailMsg:Send()
CATCH oError
    if lMsgInfo
       MsgAlert("Could not send message" + ";"  + CRLF+ ;
             "Error: " + TRANSFORM(oError:GenCode, NIL) + ";" + CRLF+;
              "SubC: "  + TRANSFORM(oError:SubCode, NIL) + ";" + CRLF+ ;
               "OSCode: "+ TRANSFORM(oError:OsCode, NIL) + ";" + CRLF +;
                "SubSystem: " + TRANSFORM(oError:SubSystem, NIL) + ";" +CRLF+ ;
                "Message: " + oError:Description )
    end
END

CursorArrow()

Return nSuccess
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: send mail
Posted: Thu May 21, 2015 01:10 PM

Dutch

I use CDO myself to send SMTP mail .. there are two factors out of the developers control in a Corporate environment and it all boils down to security.

1) You can use a local SMTP transport within a business, however most large Corporations limit SMTP traffic from ONLY KNOWN DNS targets such as multi function machines ( copiers that scan .pdf to e-mail ). And the other achilies heal is local SMTP limits e-mail to within the Company and will not allow out-bound SMTP to get past the firewall.

2) CDO is a good solution because you can set up a third party SMTP relay account, like a gmail address ( as in your example ), and point your SMTP traffic to that external address. Again, many modern Enterprises STOP ANY SMTP routing from going out through their firewall, again defeating your purpose.

To make SMTP work, you need to include any IT department in the deployment of your app that uses SMTP so they can be aware of the traffic and in ALL cases allow for the traffic to be sent from a specific DNS device.

Rick Lipkin

Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: send mail
Posted: Fri May 22, 2015 02:07 AM

Dear Rick,

I agree with you, sometime our customer has got problem in case of Firewall but it will avoid this problem by IT know what we do.

Thanks for an kind idea.

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: send mail
Posted: Mon May 25, 2015 08:30 PM

Ducth,
perhaps now I Know how send a message
but I need some info

MDNRequested := .F. what is this ?

I need the check if the email is read ..thanks

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: send mail
Posted: Tue May 26, 2015 09:12 AM

and if the final user need a proxy how I send th email ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: send mail
Posted: Tue May 26, 2015 07:17 PM
Silvio.Falconi wrote:Ducth,
perhaps now I Know how send a message
but I need some info

MDNRequested := .F. what is this ?

I need the check if the email is read ..thanks


If you or not email sending confirmation.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: send mail
Posted: Wed May 27, 2015 06:53 AM

Hello,

Many antivirus block CDO function.

Also, it does not support TLS autentification, which is now used by most ISPs.

It´s a pending issue.

Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: send mail
Posted: Wed May 27, 2015 09:33 AM

In Italy run ok with the most principal server /provider
Gmail ask a authorization to user

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion