Is there a way to send files via "send to"?

Just starting out? Need help? Post your questions and find answers here.
Kraut
New User
New User
Posts: 5
Joined: Thu Sep 29, 2022 6:50 am

Is there a way to send files via "send to"?

Post by Kraut »

Hi everybody,

I'd like to send files from my application using the windows biuld-in function "sendto/email recipient" (don't know it's name in english, can be found in explorer kontext menu). The reasons are
* I don't need to know what email client is installed
* my application's user doesn't need to know any server oder auth passwords or ...
* nothing will happen hidden behind user's back
Is there a way to do this in PureBasic? If so, I need a) a check if an email client is available and b) how to initiate an email containing one or multiple attachments. Important: The user must start the transfer by clicking the send-button, this must not happen automatically.
And wish #3: as easy as possible for an almost 60 year old beginner :wink:
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: Is there a way to send files via "send to"?

Post by Bisonte »

Here is a simple way, to start on Windows the standard email Client with some parameters :

Code: Select all

EmailAdress.s = "user@example.com"
Subject.s     = "Message Title"
Body.s        = "Message Content"

RunProgram("mailto:" + EmailAdress + "?subject=" + Subject + "&body=" + Body)
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
plouf
Enthusiast
Enthusiast
Posts: 250
Joined: Fri Apr 25, 2003 6:35 pm
Location: Athens,Greece

Re: Is there a way to send files via "send to"?

Post by plouf »

Not acctually answer to your question
But since vast majority of attachmemt are blocked nowdays and most people use "file send services" like box/onedrive etc
You may consider upload there and get link back . Which is also easy to copy it to message body to bisonte solution
Christos
Kraut
New User
New User
Posts: 5
Joined: Thu Sep 29, 2022 6:50 am

Re: Is there a way to send files via "send to"?

Post by Kraut »

Hi Bisonte,
thanks for your post. As I wrote in the headline I want to send files by email.

Code: Select all

RunProgram("mailto:" + EmailAdress + "?subject=" + Subject + "&body=" + Body)
or more precisely "mailto" does not allow attachments.

The plan was that I could use the installed e-mail client without knowing which one it is and without having to ask the user for sensitive data (password, server, ...). I wanted to prepare an email completely with subject, body, attachment and the user only has to enter the recipient and send it.

The only thing that remains is to control the respective email client via "runprogram". No problem with Thunderbird but I have no experience with Outlook or other email clients and how to use command line parameters for them. I'm grateful for any help.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Is there a way to send files via "send to"?

Post by BarryG »

Interesting info here about "mailto:" and attachments -> https://support.interact.technology/sup ... tachments-

Haven't tried it, but the author claims it's possible by using "mailto:" with a JSON config file that points to the file.

The short code there looks very simple to adapt to work with PureBasic.
Axolotl
Enthusiast
Enthusiast
Posts: 435
Joined: Wed Dec 31, 2008 3:36 pm

Re: Is there a way to send files via "send to"?

Post by Axolotl »

I'am not sure how this can be done in PureBasic.
Found some Not-PureBasic codes which should do the trick using an IDataObject.
https://mvps.org/emorcillo/en/code/vb6/sendmail.shtml
https://www.codeproject.com/articles/38 ... -recipient

Helpful, because this is based on Shell Extension stuff
https://learn.microsoft.com/en-us/windo ... shell-exts

Happy coding and stay healthy.
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
plouf
Enthusiast
Enthusiast
Posts: 250
Joined: Fri Apr 25, 2003 6:35 pm
Location: Athens,Greece

Re: Is there a way to send files via "send to"?

Post by plouf »

maybe it is sound "Better" to crate a base64 attachment to a file but i believe a service like transfer.sh is by far easier and avoids antivirus tools

transfer.bat is from transfer.sh page at bottom (click more twice)

Code: Select all

path$ = "E:\Tools\Network\transfer.sh"

RunProgramResult = RunProgram("transfer.bat","test.txt >link.txt",path$)
Delay(3000)
If ReadFile(0, path$ + "link.txt")   ; if the file could be read, we continue...
  linkurl$ = ReadString(0) 
  CloseFile(0)
  DeleteFile(path$ + "link.txt")
EndIf
 
RunProgram("mailto:" + "test@gmail.com" + "?subject=" + "File link from XYZ" + "&body=" + linkurl$)
Christos
Post Reply