Page 1 of 1

[Solved] Attachment into email with Hyperlink - mailto

Posted: Fri Nov 18, 2016 4:06 pm
by lodovi
Hello, is it possible to get attachment to email with the function Hyperlink? I have this function:

HYPERLINK("mailto:"&A1&"?subject="&B1&"&body="&C1&"&attach='c:\test.ods'";A1)

It works perfectly BUT without attachment. Can anybody to help?

(So it opening Thunderbird new email window ... maybe it is important)

Re: Attachment into email with Hyperlink - mailto

Posted: Fri Nov 18, 2016 8:08 pm
by rajew
There are a couple of subjects on this matter on mozillazine forums - Thunderbird does not accept attachment parameter in mailto links, so this is impossible. A few of the email clients will, like for ex. Evolution on LInux. You could try building a link that would invoke thunderbird with -compose param, but that would be very machine-specific (path to thunderbird exe).

Re: Attachment into email with Hyperlink - mailto

Posted: Mon Nov 21, 2016 10:47 am
by lodovi
Thank you. I tried macro from here http://ooo-forums.apache.org/en/forum/v ... 7&p=379776 but it looks like it does not work in LO (mabe only in AOO, but I do not tried it). Is it posible to use (or modify) this macro for LO

Code: Select all

Sub TestMailer

Dim eMailAddress as String
Dim eSubject as String
Dim eMailer as Object
Dim eMailClient as Object

eMailAddress = "trnka@autonapul.cz"
eSubject = "Test email"
eMailer = createUnoService("com.sun.star.system.SystemMailProvider")
eMailClient = eMailer.queryMailClient() 'Here is a mistake
eMessage = eMailClient.createMailMessage()
eMessage.Recipient = eMailAddress
eMessage.Subject = eSubject
'eMessage.CcRecipient = Array("dummy2@gmail.com")
'eMessage.BccRecipient = Array("dummy@gmail.com")
eMessage.Body = "This is the text of the test message."
AttachmentURL = convertToUrl("d:\_prace\ksefty\OO_pokusy\vzorec3.jpg")
eMessage.Attachement = Array(AttachmentURL)
eMailClient.sendMailMessage ( eMessage, com.sun.star.system.MailClientFlags.NO_USER_INTERFACE )

End Sub

Re: Attachment into email with Hyperlink - mailto

Posted: Mon Nov 21, 2016 11:10 am
by RoryOF
Look up what com.sun.star.system.SystemMailProvider offers. You will find this at
https://www.openoffice.org/api/docs/com ... vider.html
I think you need to use XSystemMailProvider.

Re: Attachment into email with Hyperlink - mailto

Posted: Mon Nov 21, 2016 11:16 am
by lodovi
RoryOF wrote:Look up what com.sun.star.system.SystemMailProvider offers. You will find this at
https://www.openoffice.org/api/docs/com ... vider.html

I think you need to use XSystemMailProvider.
OK, than you, but here http://api.libreoffice.org/docs/idl/ref ... ystem.html i can not find "XSystemMailProvider".

Re: Attachment into email with Hyperlink - mailto

Posted: Mon Nov 21, 2016 11:32 am
by RoryOF
I can't answer for what LibreOffice provides. I can find it in the OpenOffice API. If you are using LibreOffice you may need to rewrite the macro.

Re: Attachment into email with Hyperlink - mailto

Posted: Mon Nov 21, 2016 11:41 am
by Zizi64
We are using the

Code: Select all

eMailer = createUnoService( "com.sun.star.system.SimpleSystemMail" )
with LO 4.4.7 version and the Thunderbird E-mail client on Win7, and it works fine. The Thunderbird must be the default e-mail client.

Code: Select all

Dim eMailAddress as String
Dim eSubject as String
Dim eMailer as Object
Dim eMailClient as Object
Dim eMessage as Object

 	eMailAddress = "Somebody@SomeService.com"
 	eSubject = "The subject string"
	eMailer = createUnoService( "com.sun.star.system.SimpleSystemMail" )
	     
		eMailClient = eMailer.querySimpleMailClient()     
		eMessage = eMailClient.createSimpleMailMessage()
     
		eMessage.setRecipient(eMailAddress)
		eMessage.setSubject(eSubject)

		eMessage.setAttachement (Array("TheUrlOfTheAttachment"))

		eMessage.body="Body text"
		
	eMailClient.sendSimpleMailMessage( eMessage, 0 ) 'The client will pop up, and the user will send the constructer email message, manually.
'	eMailClient.sendSimpleMailMessage ( eMessage,com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE ) 'silent sending

Re: Attachment into email with Hyperlink - mailto

Posted: Mon Nov 21, 2016 12:20 pm
by lodovi
Thank very much to Zizi64. I found something similar but whitout this: eMessage.body="Body text" and I did not find a possibility here: http://api.libreoffice.org/docs/idl/ref ... ssage.html

Your code is perfect.

Re: [Solved]Attachment into email with Hyperlink - mailto

Posted: Mon Nov 21, 2016 5:01 pm
by Zizi64
I found something similar but whitout this: eMessage.body="Body text"
Use the "MRI" or the "Xray tool" extension for examine and display the existing properties, methods, interfaces of the objects.

Re: [Solved]Attachment into email with Hyperlink - mailto

Posted: Tue Nov 22, 2016 9:31 pm
by lodovi
Here is complete solution. First is for button and second is for HYPERLINK.

Code: Select all

=HYPERLINK("vnd.sun.star.script:Standard.Module1.HyperSendMail?language=Basic&location=document&MailAddress="&A1&"&Subject="&A2&"&Body="&A3&"&Attach="&A4;"Send e-mail")
and macros. Everything is testing only in LO 5.2.

Code: Select all

Sub SendMail 'this is solution for button (variables in czech language)
doc = thisComponent
list = doc.getCurrentController.getActiveSheet
adresa = list.GetCellRangeByName("A1").string
predmet = list.GetCellRangeByName("A2").string
telo = list.GetCellRangeByName("A3").string
priloha = list.GetCellRangeByName("A4").string

Mailer (adresa, predmet, telo, priloha)

end sub

Sub HyperSendMail (sURL$) 'this is solution for function HYPERLINK in the sheet (variables in czech language)

adresa = getArgumentFromURL(sURL,"MailAddress")
predmet = getArgumentFromURL(sURL, "Subject")
telo = getArgumentFromURL(sURL, "Body")
priloha = getArgumentFromURL(sURL, "Attach")

Mailer (adresa, predmet, telo, priloha)

End Sub


Sub Mailer (eMailAddress as String, eSubject as String, eBody as String, Attachment as String)

Dim eMailer as Object
Dim eMailClient as Object
Dim eMessage as Object
Dim nFlag as integer

   
   nFlag = 0
   eMailer = createUnoService( "com.sun.star.system.SimpleSystemMail" )
        
      eMailClient = eMailer.querySimpleMailClient()     
      eMessage = eMailClient.createSimpleMailMessage()
     
      eMessage.setRecipient(eMailAddress)
      eMessage.setSubject(eSubject)

      if Attachment <> "" Then  
         eAttachmentURL = convertToUrl(Attachment)
         eMessage.setAttachement (Array(eAttachmentURL))
      end if   
      
      eBody = Replace(eBody,"*",chr(10))

      eMessage.body = eBody
      
   eMailClient.sendSimpleMailMessage( eMessage, nFlag)

End Sub


REM returns "" if no value was found for name.
Function getArgumentFromURL(sURL$,sName$) as String
on error goto exitErr:
Dim iStart%, i%, l%, sArgs$, a()
   iStart = instr(sURL, "?")
   l = len(sName)
   if (iStart = 0) or (l = 0) then exit function
   ' sArgs behind "?":
   sArgs = mid(sURL, iStart +1)
   a() = split(sArgs, "&")
   for i = 0 to uBound(a())
      ' not case sensitive:
      if instr(1, a(i), sName &"=", 1) = 1 then
         getArgumentFromURL = mid(a(i), l +2)
         exit for
      endif
   next
exitErr:
' return ""
End Function

Re: [Solved]Attachment into email with Hyperlink - mailto

Posted: Tue Nov 22, 2016 9:40 pm
by Villeroy
You know that address, subject, body and attachment path must not contain = nor & :P

I'd suggest range arguments SH, SR, ER, SC, EC for sheet, start row, end row, start column and end column using SHEET(), ROW(), COLUMN() with offsets
"&SH="&SHEET()&"&SR="&ROW()&"&EH="&ROW()&"&SC=1&EC=4"
which gives in row #3 of sheet #1
&SH=1&SR=3&ER=3&SC=1&EC=4
referring to columns A to D in this column on this sheet.
The macro fetches the range like this:
ThisComponent.Sheets(sh -1).getCellRangeByPosition(sc -1, sr -1, ec -1, er -1)