añadir firma al mail

HMG en Español

Moderator: Rathinagiri

User avatar
AidTIC
Posts: 117
Joined: Mon Apr 22, 2013 8:29 am
DBs Used: DBF
Contact:

añadir firma al mail

Post by AidTIC »

Hola,
Tengo una aplicación que manda correo con archivos adjunto desde distintos puestos de trabajo.
y me gustaría que ver si hay alguna forma que el cuerpo del mail su completara con la firma que ya tiene el cliente en outllook.
Gracias

Hello,
I have an application that sends email with attachments from different jobs.
And I would like to see if there is any way that the body of the email could be completed with the signature that the client already has in Outlook.
Thank you.

Code: Select all

oOutLook := CreateObject("Outlook.Application")
 oMail := oOutLook:CreateItem(0)
 oRecip := oMail:Recipients
 oRecip:Add( cDestino )
 oAdjunto:=oMail:Attachments
 oAdjunto:Add( cAnexo )
 oMail:Subject := cAssunto
 oMail:BodyFormat = 2
 oMail:HTMLBody := MEMOREAD( GetStartUpFolder()+"\Plantilla\mailcfg.html" )
 oMail:HTMLBody += '<p class="style1">Estimado Cliente,</p>'
 oMail:HTMLBody += '<p class="style1">Adjunto les remitimos para su contabilidad, nuestra factura en formato PDF por la prestaci'+ chr(162)+'n de servicios.  Para cualquier consulta sobre la misma, por favor no duden en ponerse en contacto con nosotros.</p>'
 oMail:HTMLBody += '<p class="style1">La factura es un documento generado electr'+ chr(162)+'nicamente, con el mismo contenido y validez tributaria que la factura tradicional en papel. El Real Decreto 1619/2012 aprueba el reglamento que regula esta modalidad de facturaci'+ chr(162)+'n.</p>'
 oMail:HTMLBody += '<p class="style1">Sin otro particular, reciba un cordial saludo.</p>'
 oMail:HTMLBody += '<p class="style1"></p>'
 oMail:HTMLBody += '</body></html>'
 oMail:Display()
Skydone Solutions
www.skydone.com
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: añadir firma al mail

Post by edk »

The easiest way is to do a trick in which, after displaying an empty message, Outlook will add the signature assigned to the account, then copy this signature and add it to the message body at the end of your message.

Code: Select all

oOutLook := CreateObject("Outlook.Application")
 oMail := oOutLook:CreateItem(0)
 oMail:Display()
 cSignature := oMail:HTMLBody		/* store default mail account signature */
 oRecip := oMail:Recipients
 oRecip:Add( cDestino )
 oAdjunto:=oMail:Attachments
 oAdjunto:Add( cAnexo )
 oMail:Subject := cAssunto
 oMail:BodyFormat = 2
 oMail:HTMLBody := MEMOREAD( GetStartUpFolder()+"\Plantilla\mailcfg.html" )
 oMail:HTMLBody += '<p class="style1">Estimado Cliente,</p>'
 oMail:HTMLBody += '<p class="style1">Adjunto les remitimos para su contabilidad, nuestra factura en formato PDF por la prestaci'+ chr(162)+'n de servicios.  Para cualquier consulta sobre la misma, por favor no duden en ponerse en contacto con nosotros.</p>'
 oMail:HTMLBody += '<p class="style1">La factura es un documento generado electr'+ chr(162)+'nicamente, con el mismo contenido y validez tributaria que la factura tradicional en papel. El Real Decreto 1619/2012 aprueba el reglamento que regula esta modalidad de facturaci'+ chr(162)+'n.</p>'
 oMail:HTMLBody += '<p class="style1">Sin otro particular, reciba un cordial saludo.</p>'
 oMail:HTMLBody += '<p class="style1"></p>'
 oMail:HTMLBody += '</body></html>'
 oMail:HTMLBody += cSignature		/* restore default mail account signature */
 //oMail:Display()
User avatar
AidTIC
Posts: 117
Joined: Mon Apr 22, 2013 8:29 am
DBs Used: DBF
Contact:

Re: añadir firma al mail

Post by AidTIC »

Muchas Gracias edk
Me funciona.

Para perfilarlo, me saltas 2 líneas entre el cuerpo que yo genero la firma.

Thank you very much edk
It FUNCION.

To outline it, you skip 2 lines between the body that I generate the signature.
Captura de pantalla 2023-11-21 132752.png
Captura de pantalla 2023-11-21 132752.png (34.88 KiB) Viewed 47980 times
Skydone Solutions
www.skydone.com
franco
Posts: 889
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: añadir firma al mail

Post by franco »

Hello, use gmail for my emails directly sending invoices and other sales information for my POS program and it works very well with gmails 2 step verification. I do have a problem with some users changing the sending password which is set by google, then program will not work so have to get new one from google. Does anyone have a complete uncomplicated sample of outlook email. I can find in the forum different parts, but not a complete
easy sample.
Thanks in advance.
All The Best,
Franco
Canada
User avatar
AidTIC
Posts: 117
Joined: Mon Apr 22, 2013 8:29 am
DBs Used: DBF
Contact:

Re: añadir firma al mail

Post by AidTIC »

Con el código que he puesto se crea un mail en outlook directamente con el remitente predeterminado que tengas.
Skydone Solutions
www.skydone.com
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: añadir firma al mail

Post by edk »

AidTIC wrote: Tue Nov 21, 2023 12:35 pm Muchas Gracias edk
Me funciona.

Para perfilarlo, me saltas 2 líneas entre el cuerpo que yo genero la firma.

Thank you very much edk
It FUNCION.

To outline it, you skip 2 lines between the body that I generate the signature.

Captura de pantalla 2023-11-21 132752.png
You can also try inserting a signature directly from your Outlook signature file.

Outlook signatures are stored in this location: %APPDATA%\Microsoft\Signatures\

This is the function that reads these signatures and changes the indirect links to direct ones internally: GetOutlookSignature ( cSignatureFile )
As an argument, you can provide the name of a .htm file with the selected signature if there are several of them defined in Outlook.
If you do not provide a file name, the first one appearing alphabetically in this folder will be read.

Code: Select all

oOutLook := CreateObject("Outlook.Application")
oMail := oOutLook:CreateItem(0)

oRecip := oMail:Recipients
oRecip:Add( cDestino )
oAdjunto:=oMail:Attachments
oAdjunto:Add( cAnexo )
oMail:Subject := cAssunto
oMail:BodyFormat = 2
oMail:HTMLBody := MEMOREAD( GetStartUpFolder()+"\Plantilla\mailcfg.html" )
oMail:HTMLBody += '<p class="style1">Estimado Cliente,</p>'
oMail:HTMLBody += '<p class="style1">Adjunto les remitimos para su contabilidad, nuestra factura en formato PDF por la prestaci'+ chr(162)+'n de servicios.  Para cualquier consulta sobre la misma, por favor no duden en ponerse en contacto con nosotros.</p>'
oMail:HTMLBody += '<p class="style1">La factura es un documento generado electr'+ chr(162)+'nicamente, con el mismo contenido y validez tributaria que la factura tradicional en papel. El Real Decreto 1619/2012 aprueba el reglamento que regula esta modalidad de facturaci'+ chr(162)+'n.</p>'
oMail:HTMLBody += '<p class="style1">Sin otro particular, reciba un cordial saludo.</p>'
oMail:HTMLBody += '<p class="style1"></p>'
*oMail:HTMLBody += '</body></html>'
oMail:HTMLBody += GetOutlookSignature()
oMail:Display()
*****************************************
Function GetOutlookSignature ( cSignatureFile )
Local cDirWithSignatures := hb_GetEnv( "APPDATA" ) + "\Microsoft\Signatures\"
Local cSearchForFile := IF ( Empty ( cSignatureFile ), "*.htm", cSignatureFile )
Local aFiles, cSignature := "", cFileRef
aFiles := hb_Directory( cDirWithSignatures + cSearchForFile )
IF Empty ( aFiles )
    RETURN cSignature   //there is no signature files
ENDIF
//cSignature := FileStr ( cDirWithSignatures + aFiles [ 1 ] [ 1 ] )
cSignature := CreateObject( "Scripting.FileSystemObject" ):GetFile( cDirWithSignatures + aFiles [ 1 ] [ 1 ] ):OpenAsTextStream( 1, -2 ):ReadAll
cFileRef   := StrTran ( hb_FNameName( aFiles [ 1 ] [ 1 ] ) + "_", " ", "%20" )
cSignature := StrTran ( cSignature, cFileRef, "file:///" + cDirWithSignatures + cFileRef )
RETURN cSignature
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: añadir firma al mail

Post by edk »

franco wrote: Tue Nov 21, 2023 7:23 pm Hello, use gmail for my emails directly sending invoices and other sales information for my POS program and it works very well with gmails 2 step verification. I do have a problem with some users changing the sending password which is set by google, then program will not work so have to get new one from google. Does anyone have a complete uncomplicated sample of outlook email. I can find in the forum different parts, but not a complete
easy sample.
Thanks in advance.
Sample for sending a message via Outlook

Code: Select all

cTo         := "someemail@email.com"
cSubject    := "Any subject"
cAttachment := HB_CWD() + "FV254.pdf"


oOutLook := CreateObject( "Outlook.Application" )
oNS      := oOutLook:GetNamespace( "MAPI" )
oNS:Logon()

oMail        := oOutLook:CreateItem(0)	//create a new message object
oRecip       := oMail:Recipients			//recipients object
oRecipAddres := oRecip:Add( cTo )		//add recipient

oRecipAddres:Resolve()
If oRecipAddres:Resolved		//check to addres is valid
    
    oAttachment := oMail:Attachments
    oAttachment:Add( cAttachment )		    //add attachment
    
    oMail:Subject := cSubject		
    
    oMail:BodyFormat = 2		//html
    
    oMail:HTMLBody := "<Html><Heah><Title>Sample Message</Title></Head><Body>"
    oMail:HTMLBody += "<p>Hello, a testing message ...</p>" 
    oMail:HTMLBody += '</Body></Html>'
    
    //oMail:Display()
    oMail:Send()
Else
    MsgStop ( "There is no such record in your address book." )
End If

oNS:Logoff()

//clean up
oRecipAddres := Nil
oRecip       := Nil
oAdjunto     := Nil
oMail        := Nil
oNS          := Nil
oOutlook     := Nil
franco
Posts: 889
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: añadir firma al mail

Post by franco »

I guess I am not very smart.
I get to createobject line. I have never figured out how createobject works.

Code: Select all

Function main
cTo         := "myrecieving.gmail"
cSubject    := "Any subject"
cAttachment := HB_CWD() + 'cen9097.pdf'          // local pdf file                               HB_CWD() + "FV254.pdf"


oOutLook := CreateObject( "Outlook.Application" )     
oNS      := oOutLook:GetNamespace( "MAPI" )
oNS:Logon()
All The Best,
Franco
Canada
User avatar
AidTIC
Posts: 117
Joined: Mon Apr 22, 2013 8:29 am
DBs Used: DBF
Contact:

Re: añadir firma al mail

Post by AidTIC »

edk wrote: Wed Nov 22, 2023 2:50 pm
AidTIC wrote: Tue Nov 21, 2023 12:35 pm Muchas Gracias edk
Me funciona.

Para perfilarlo, me saltas 2 líneas entre el cuerpo que yo genero la firma.

Thank you very much edk
It FUNCION.

To outline it, you skip 2 lines between the body that I generate the signature.

Captura de pantalla 2023-11-21 132752.png
You can also try inserting a signature directly from your Outlook signature file.

Outlook signatures are stored in this location: %APPDATA%\Microsoft\Signatures\

This is the function that reads these signatures and changes the indirect links to direct ones internally: GetOutlookSignature ( cSignatureFile )
As an argument, you can provide the name of a .htm file with the selected signature if there are several of them defined in Outlook.
If you do not provide a file name, the first one appearing alphabetically in this folder will be read.

Code: Select all

oOutLook := CreateObject("Outlook.Application")
oMail := oOutLook:CreateItem(0)

oRecip := oMail:Recipients
oRecip:Add( cDestino )
oAdjunto:=oMail:Attachments
oAdjunto:Add( cAnexo )
oMail:Subject := cAssunto
oMail:BodyFormat = 2
oMail:HTMLBody := MEMOREAD( GetStartUpFolder()+"\Plantilla\mailcfg.html" )
oMail:HTMLBody += '<p class="style1">Estimado Cliente,</p>'
oMail:HTMLBody += '<p class="style1">Adjunto les remitimos para su contabilidad, nuestra factura en formato PDF por la prestaci'+ chr(162)+'n de servicios.  Para cualquier consulta sobre la misma, por favor no duden en ponerse en contacto con nosotros.</p>'
oMail:HTMLBody += '<p class="style1">La factura es un documento generado electr'+ chr(162)+'nicamente, con el mismo contenido y validez tributaria que la factura tradicional en papel. El Real Decreto 1619/2012 aprueba el reglamento que regula esta modalidad de facturaci'+ chr(162)+'n.</p>'
oMail:HTMLBody += '<p class="style1">Sin otro particular, reciba un cordial saludo.</p>'
oMail:HTMLBody += '<p class="style1"></p>'
*oMail:HTMLBody += '</body></html>'
oMail:HTMLBody += GetOutlookSignature()
oMail:Display()
*****************************************
Function GetOutlookSignature ( cSignatureFile )
Local cDirWithSignatures := hb_GetEnv( "APPDATA" ) + "\Microsoft\Signatures\"
Local cSearchForFile := IF ( Empty ( cSignatureFile ), "*.htm", cSignatureFile )
Local aFiles, cSignature := "", cFileRef
aFiles := hb_Directory( cDirWithSignatures + cSearchForFile )
IF Empty ( aFiles )
    RETURN cSignature   //there is no signature files
ENDIF
//cSignature := FileStr ( cDirWithSignatures + aFiles [ 1 ] [ 1 ] )
cSignature := CreateObject( "Scripting.FileSystemObject" ):GetFile( cDirWithSignatures + aFiles [ 1 ] [ 1 ] ):OpenAsTextStream( 1, -2 ):ReadAll
cFileRef   := StrTran ( hb_FNameName( aFiles [ 1 ] [ 1 ] ) + "_", " ", "%20" )
cSignature := StrTran ( cSignature, cFileRef, "file:///" + cDirWithSignatures + cFileRef )
RETURN cSignature
Muchas Gracias, me funciona perfectamente.

Thank you very much, it works perfectly for me.
Skydone Solutions
www.skydone.com
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: añadir firma al mail

Post by edk »

franco wrote: Thu Nov 23, 2023 1:22 am I guess I am not very smart.
I get to createobject line. I have never figured out how createobject works.

Code: Select all

Function main
cTo         := "myrecieving.gmail"
cSubject    := "Any subject"
cAttachment := HB_CWD() + 'cen9097.pdf'          // local pdf file                               HB_CWD() + "FV254.pdf"


oOutLook := CreateObject( "Outlook.Application" )     
oNS      := oOutLook:GetNamespace( "MAPI" )
oNS:Logon()
https://learn.microsoft.com/en-us/offic ... tnamespace
https://learn.microsoft.com/en-us/offic ... of-outlook
Post Reply