send mail

send mail

Postby Silvio.Falconi » Wed May 20, 2015 7: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6768
Joined: Thu Oct 18, 2012 7:17 pm

Re: send mail

Postby dutch » Thu May 21, 2015 12:51 am

This is what I use.
Code: Select all  Expand view
*-------------------------------------------------------------------------------------------------------------------------------*
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 19.01 / 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)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: send mail

Postby Rick Lipkin » Thu May 21, 2015 1: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
User avatar
Rick Lipkin
 
Posts: 2615
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: send mail

Postby dutch » Fri May 22, 2015 2: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 19.01 / 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)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: send mail

Postby Silvio.Falconi » Mon May 25, 2015 8: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6768
Joined: Thu Oct 18, 2012 7:17 pm

Re: send mail

Postby Silvio.Falconi » Tue May 26, 2015 9: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6768
Joined: Thu Oct 18, 2012 7:17 pm

Re: send mail

Postby karinha » Tue May 26, 2015 7: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
User avatar
karinha
 
Posts: 7213
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: send mail

Postby lucasdebeltran » Wed May 27, 2015 6: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.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: send mail

Postby Silvio.Falconi » Wed May 27, 2015 9: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6768
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests