Hi,
Can anyone recommend a reliable solution to send Emails from the Fivewin application?
Regards
Anser
Ruth wrote:Dear Mr. Santos, I would greatly appreciate your example. May I kindly ask for it...
I use (am learning) MOD_HARBOUR and desktop
Kind regards Ruth
anserkk wrote:Hi,
Can anyone recommend a reliable solution to send Emails from the Fivewin application?
Regards
Anser
static Function EmailProva2(cNomeMittente,cMailMittente,cServerSmtp,nPorta,cNomeUtente,cPassword,lcopianascostaalmittente,cmail)
Local nBottom := 33.2
Local nRight := 58
Local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
Local nHeight := nBottom * DLG_CHARPIX_H
Local oDlgTest
Local cDlgTitle := "Invio Email di Prova"
Local aGet[10]
local oTitle1,oImagetitle
local cImageTitle:= "Mail2.bmp"
local oFont2,oFontBold2,oFontBold3
local obtn2[3]
local nItem := 0
local x
local lRet := .f.
local cSubject:="Email di prova"
local cMessage:="Questa è una e-mail di prova inviata da ..."
local cCC:= space(60)
local cCCn:= IIF( lcopianascostaalmittente,cMailMittente,space(60))
local oMsg := CreateObject( "CDO.Message" )
local oConf := CreateObject( "CDO.Configuration" )
local cSchema := "http://schemas.microsoft.com/cdo/configuration/"
local oBtn1,oBtn3
IF empty(cNomeMittente)
msginfo("Inserire il nome utente")
return nil
Endif
IF empty(cMailMittente)
msginfo("Inserire la casella di posta")
return nil
Endif
IF empty(cPassword)
msginfo("Inserire la password")
return nil
Endif
DEFINE FONT oFont2 NAME 'Tahoma' SIZE 0, -12
DEFINE FONT oFontBold2 NAME 'Tahoma' SIZE 0, -18 BOLD
DEFINE FONT oFontBold3 NAME 'Tahoma' SIZE 0, -12 BOLD
DEFINE DIALOG oDlgTest ;
SIZE nWidth, nHeight PIXEL ;
TITLE cDlgTitle
oDlgTest:lHelpIcon := .F.
oDlgTest:nStyle := nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, 4 )
@ 0,0 TITLE oTitle1 OF oDlgTest size 500, 40 SHADOW NOSHADOW ;
GRADIENT { { 1,CLR_WHITE, LIGHTCYAN } }
@ 10, 12 TITLETEXT OF oTitle1 TEXT "Invio e-mail" FONT oFontBold2 COLOR CLR_BLACK
@ 38, 42 TITLETEXT OF oTitle1 TEXT "Inserisci destinatari e testo del messaggio" FONT oFont2 COLOR CLR_BLACK
@ 10, oTitle1:nWidth-120 TITLEIMG oImagetitle OF oTitle1 BITMAP cImageTitle TRANSPARENT
@ 50 , 10 SAY "A:" of oDlgTest size 80,10 PIXEL FONT oFontBold3 COLOR CLR_BLACK
@ 50,50 GET aGet[1] VAR cMailMittente size 170,10 PIXEL FONT oFont2 UPDATE
@ 70 , 10 SAY "Oggetto:" of oDlgTest size 80,10 PIXEL FONT oFontBold3 COLOR CLR_BLACK
@ 70,50 GET aGet[2] VAR cSubject size 170,10 PIXEL FONT oFont2 UPDATE
@ 90 , 10 SAY "CC:" of oDlgTest size 80,10 PIXEL FONT oFontBold3 COLOR CLR_BLACK
@ 90,50 GET aGet[3] VAR cCC size 170,10 PIXEL FONT oFont2 UPDATE
@ 110 , 10 SAY "CCn:" of oDlgTest size 80,10 PIXEL FONT oFontBold3 COLOR CLR_BLACK
@ 110,50 GET aGet[4] VAR cCCn size 170,10 PIXEL FONT oFont2 UPDATE
@ 130,50 GET aGet[5] VAR cMessage size 170,45 PIXEL FONT oFont2 UPDATE MEMO
@ 185,50 ListBox oList Var nItem ITEMS aAttach Size 170,50 Pixel
* @ 190, 25 Button "Agg" Size 20,08 Pixel Action ADDItem()
* @ 205, 25 Button "Can" Size 20,08 Pixel Action DELItem()
oBtn1:= TUrlLink():New( 190, 2, oDlgTest, .T., .F., oFont2, "Aggiungi", "Aggiungi allegato" )
oBtn1:bAction := { |nRow, nCol| ADDItem() }
oBtn3:= TUrlLink():New( 205, 2, oDlgTest, .T., .F., oFont2, "Cancella", "Cancella allegato" )
oBtn3:bAction := { |nRow, nCol| DELItem() }
@ 236, 120 Button obtn2[2] Prompt "&Conferma" of oDlgTest size 50,12 PIXEL FONT oFont2 DEFAULT ACTION ( oDlgTest:end( IDOK ) )
@ 236, 175 Button obtn2[3] Prompt "&Annulla" of oDlgTest size 50,12 PIXEL FONT oFont2 CANCEL ACTION ( oDlgTest:end( IDCANCEL ) )
ACTIVATE DIALOG oDlgTest centered
if oDlgTest:nresult == IDOK
//============================================================================================//
TRY
oCfg := CREATEOBJECT( "CDO.Configuration" )
WITH OBJECT oCfg:Fields
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := alltrim(cServerSmtp)
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := val(alltrim(nPorta))
: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 := .t.
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value := alltrim(cNomeUtente)
:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := alltrim(cPassword)
:Update()
END WITH
lRet := .t.
CATCH oError
MsgInfo( "Non è possibile inviare l'email!!!" +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+ ;
"Messaggio: " + oError:Description, "Attenzione" )
END
if lRet
TRY
oMsg:To = alltrim(cmail)
oMsg:From =chr(34)+alltrim(cNomeMittente)+" "+chr(34)+ "<"+alltrim(cMailMittente)+">"
oMsg:Subject = alltrim(cSubject)
oMsg:HTMLBody = alltrim(cMessage)
oMsg:Sender = alltrim(cNomeMittente)
oMsg:Organization = "Family"
IF lcopianascostaalmittente
oMsg:ReplyTo = alltrim(cMailMittente)
endif
For x := 1 To Len( aAttach )
if aAttach[x] <> NIL
oMsg:AddAttachment(AllTrim(aAttach[x]))
endif
Next
oMsg:Configuration = oCfg
oMsg:Send()
CATCH
MsgInfo("Non è possibile inviare il messaggio di posta")
lRet := .f.
END
endif
Endif
//============================================================================================//
return nil
// C:\FWH\SAMPLES\RUTHMAIL.PRG
#include "FiveWin.ch"
MEMVAR smtpserver, serverport, sendusing, authenticate, usessl, username, ;
password, timeout
MEMVAR cFrom, cTo, cSubject, cTextBody
FUNCTION Main()
PRIV smtpserver, serverport, sendusing, authenticate, usessl, username, ;
password, timeout
PRIV cFrom, cTo, cSubject, cTextBody
smtpserver := "smtp.pleno.com.br"
serverport := 587
sendusing := 2
authenticate := .T.
usessl := .F. // .T. or .F.
username := "joao@pleno.com.br" //<your_email>
password := "XXXXXXX" // <sua_senha>
timeout := 60
cFrom := "joao@pleno.com.br"
cTo := "kapiabafwh@gmail.com"
cSubject := "RUTH send with Gmail account RUTH"
cTextBody := "RUTH: Teste de Email-Only TEST"
SendMailCDO()
RETURN NIL
FUNCTION SendMailCDO()
LOCAL objMsg, cHtml, oError
LOCAL msgConf, lRet := .F.
/*
? smtpserver, serverport, sendusing, authenticate, usessl, username, ;
password, timeout
*/
//' Server Configuration
TRY
msgConf := CreateObject("CDO.Configuration")
WITH OBJECT msgConf:Fields
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := smtpserver
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := serverport
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value := sendusing
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := authenticate
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value := usessl
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value := username
:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := password
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := timeout
:Update()
END WITH
CATCH oError
MsgInfo("Configuration instance object error " + ";" + 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
//' Email
TRY
objMsg := CreateObject("CDO.Message")
WITH OBJECT objMsg
:Configuration := msgConf
:From := cFrom
:To := cTo
:Subject := cSubject
:TextBody := cTextBody
:MDNRequested := .F. // Indicates whether a Message Disposition Notification is requested on a message.
:Send()
END WITH
// objMsg:Send()
lRet := .T.
CATCH oError
MsgInfo("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 )
RETURN NIL
END
IF lRet // := .T.
? "PERFECT RUTH"
ENDIF
RETURN NIL
// FIN / END - kapiabafwh@gmail.com
// C:\FWH\SAMPLES\RUTHMAIL.PRG
#include "FiveWin.ch"
#Include "Outlook.ch"
#Include "Mail.ch"
MEMVAR smtpserver, serverport, sendusing, authenticate, usessl, username, ;
password, timeout
MEMVAR cFrom, cTo, cSubject, cTextBody, cImgBase64, cImg, cBase64
FUNCTION Main()
PRIV smtpserver, serverport, sendusing, authenticate, usessl, username, ;
password, timeout
PRIV cFrom, cTo, cSubject, cTextBody, cImgBase64
smtpserver := "smtp.iomartmail.com"
serverport := 587
sendusing := 2
authenticate := .T.
usessl := .F. // .T. or .F.
username := "" //<your_email>
password := "" // <sua_senha>
timeout := 60
cFrom := "info@winhotel.at"
cTo := "hotel@bergland.info"
cSubject := "RUTH an RUTH"
// cTextBody := "RUTH: Teste de Email-Only TEST"
cImgBase64 := hb_base64encode(MEMOREAD("c:\fwh\samples\img\start_slide1.jpg"))
SendMailCDO()
RETURN NIL
FUNCTION SendMailCDO()
LOCAL objMsg, cHtml, oError
LOCAL msgConf, lRet := .F.
/*
? smtpserver, serverport, sendusing, authenticate, usessl, username, ;
password, timeout
*/
//' Server Configuration
TRY
msgConf := CreateObject("CDO.Configuration")
WITH OBJECT msgConf:Fields
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := smtpserver
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := serverport
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value := sendusing
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := authenticate
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value := usessl
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value := username
:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := password
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := timeout
:Update()
END WITH
CATCH oError
MsgInfo("Configuration instance object error " + ";" + 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
//' Email
TRY
objMsg := CreateObject("CDO.Message")
WITH OBJECT objMsg
:Configuration := msgConf
:From := cFrom
:To := cTo
:Subject := cSubject
// :TextBody := cTextBody
:HTMLBody := '<h1>HTML Content Here</h1><p>This is a TEST MAIL sent from FiveWin using CDO.</p>';
+ '<img src="https://bergland.info/img/start_slide1.jpg" >';
// + '<img src="data:image/jpeg;base64,' + cImgBase64 + '" > ';
+ '<p><b>Test Ende</b></p>' // HTML formatted content
:MDNRequested := .F. // Indicates whether a Message Disposition Notification is requested on a message.
:Send()
END WITH
// objMsg:Send()
lRet := .T.
CATCH oError
MsgInfo("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 )
RETURN NIL
END
IF lRet // := .T.
? "PERFECT RUTH"
ENDIF
RETURN NIL
// FIN / END - kapiabafwh@gmail.com
hb_base64encode(MEMOREAD("c:\fwh\samples\img\start_slide1.jpg"))
<img src="data:image/jpeg;base64,' + cImgBase64 + '" >
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 77 guests