Windows SendTo from script - windows

I'm writing an application where I have to send an email with an attachment using the default mail application.
Before the email is sent, I want the user to be able to edit the text, i.e. the application should just open the mail client with pre-filled recipient and attachment and give the user the opportunity to send it.
At very minimum I need the same effect I'd got if I selected "SendTo/Mail Recipient" from the context menu of the file.
Solutions based on the "mailto:" trick won't work as there are mail clients that do not support the "attachment=" part.
The most complete solution I've found is this one:
http://www.codeproject.com/Articles/3839/SendTo-mail-recipient
but it seems a lot of code for something so simple! (and also crashes when compiled with VS2008)
Is there any other option? It would be ok even if it was an external tool or script (e.g. a .vbs script to be launched with cscript).

I would advise you to use MAPI (Messaging Application Program Interface).
If dotNet can be part of the solution, here's a ready-to-use class in C# : Class for creating MAPI Mail Messages. It would give you something like this:
MapiMailMessage message = new MapiMailMessage("Test Message", "Test Body");
message.Recipients.Add("Test#Test.com");
message.Files.Add(#"C:\del.txt");
message.ShowDialog();
Otherwise, you can always do it in C++ if you feel confortable with it, like this answer suggest.
Then, you will be able to ShellExecute the binary executable and pass it some parameters.
Hope this helps :-)

Related

Is it possible to embed an Outlook .msg into an application using OLE?

If you have some application with an ordinary HWND, is it possible to embed an Outlook email .msg file into the window using OLE?
It appears that, after opening an Outlook message using OpenSharedItem, you can successfully QueryInterface for IOleObject. But after that, I can't seem to successfully call any IOleObject methods.
Thanks for any input.
MSG file format is well-described in MSDN. So, you can read the content without any third-party components or interfaces. To display the content (I guess the message body) you can use any web browser (for example, WebView2). The message body (HTMLBody) is represented by a regular web page. Most probably you will also need attached files that are used in the body.
Another possible alternative to use Extended MAPI for getting item properties. For example, you can use any third-party components for simplifying the work - Redemption.

Send Email with pdf file as attachment in rhomobile

I want to send email using mailto tag with a single pdf file as attachment.
mailto tag opens the mail window with passed arguments like to and subject using:
Mail to Manager
But, attachments as a parameter isnt working.
Please suggest how to send pdf attachment in rhomobile.
Thanks
I think that you need to add the physical path to the PDF file for it to work (otherwise it may not know where the file is). This post on a forum says as follows:
The only problem is that this "mailto" command executes on the
client machine, therefore it tries to locate the attachment file by
a physical path, and not by a virtual path.
That is,
Using mailto:iudith.m#zim.co.il?subject=my report&body=see attachment&attachment="\myhost\myfolder\myfile.lis"
works ok, but only for local users (those connected to the same
network as the "myhost" machine).
Using mailto:iudith.m#zim.co.il?subject=my report&body=see attachment&attachment="http://myhost:myport/my_location_virtual_path/myfile.lis"
does not work, it does not recognize such a syntax as valid for
the attachment file.
In your case you would properbly need to look at this part of the Rhomobile docs (on file system access) to get the right path to your file.
EDIT:
From you comment I can see that you are trying to make it work on iOS (due to the iOS specific path).
In this discussion (from Rhomobile's Google Group) it is explained that mailto doesn't support attachments on iOS. It says as follows:
Don't know about other platforms, but you cannot do this on iOS. mailto: does not support attachments on iOS.
You can do it using a native API, MFMailComposeViewController.
This is a complete controller with UI, so you would have to write a Native View Extension to use it:
http://docs.rhomobile.com/rhodes/extensions#native-view-extensions
EDIT 2:
I've looked around and it seems that mailto doesn't support attachments on Android either. This is because Android supports the RFC 2368 mailto protocol, which doesn't include attachments. Here is a reference to the Android mailto url parser.
I would suggest that you do as suggested for iOS, write a native extension. I think this post would be relevant for you.

Automator / AppleScript to process incoming emails in Mac Mail

I'm designing an app that allows users to email me crash reports if my app ever crashes. I'd like to leave Mac Mail running on a computer and when an email comes through, an automator script / AppleScript runs to process the contents of the body of the email.
I've got the entire parsing/processing done in a python script, except I have to manually copy the contents of the email into a file and then run my parser on that file.
What's the best way to set this up so I can the contents of the email be pushed into my parsing script?
Many thanks!
Probably the simplest approach is to define a Mail.app Rule. You can set up filtering conditions to specify the set of incoming email to apply the rule to and among the rule actions you can specify is one to run an AppleScript on incoming messages. Rules are managed with Mail.app Preferences -> Rules. Apple supplies examples of Rule Action scripts with Mac OS X. Look in /Library/Scripts/Mail Scripts/Rule Actions or search the web.
Here's a script that extracts from email into a file using a mail rule: MacScripter / Mail rule script for message export. Might be good for sample code for what you're doing.
Use the Dictionary in Applescript Editor to see the properties of mail and you'll quickly be able to see the properties of any mail message. Here's a quick and dirty example of getting the content of a mail message.
tell application "Mail"
set the_messages to selection
repeat with this_message in the_messages
set mytext to content of this_message
end repeat
end tell
Modify the script linked to above that copies output to a temporary file and then pass that file to your Python script to act on.

What's wrong with this Applescript?

My app has some rudimentary applescriptability. There is one method (receivedInstantMessage) that takes a single parameter (message) and passes it to my app which then processes it.
The following applescript:
tell application "MyApp"
receivedInstantMessage "This is a message"
end tell
Works perfectly. My app presents a dialog containing the message ("This is a message").
I'm trying to set it up so that when I send an IM to iChat, it runs an applescript that will send the contents of the message to my app. I have told iChat to run a script when a message is received and I know that part is working. The script I am now using does not work:
using terms from application "iChat"
on message received theMessage from theBuddy for theChat
tell application "MyApp"
receivedInstantMessage theMessage
end tell
end message received
end using terms from
Nothing happens when I receive a message. Even if I substitute the message variable (theMessage) from iChat and use an arbitrary string it still does nothing.
What am I doing wrong. I'm quite new to applescript (being a REALbasic coder normally).
[Update]: This seems to work now. A simple restart of the Mac fixed things. Very odd...
just a semantic detail: Consider the scripter is sending messages to your app, not receiving them. Yes, your app is receiving them, but the terminology you chose "receivedInstantMessage" is from the point of view of your app, not the scripter.
Additionally, it is considered naff to have terminology in camel case. AppleScript terminology can (and often should) contain spaces. And if you really want to do it properly you should separate the terminology into nouns and verbs. (Where nouns are properly-modelled objects, with properties, and verbs are commands for manipulating them. In this case you probably want something like send message "bla", where a message is an object with properties like sender, recipient, channel etc. and send is a command which takes a message object as a parameter - check the dictionary of Snak for a quite nice - but not perfect - implementation).
Sorry if this sounds anal. I have been applescripting for many years, and while I really appreciate it when developers add applescript support, I know I speak for all applescripters when I say that poorly constructed dictionaries, and poor terminology choices are frustrating and irritating, especially as the app gets more mature and the developer starts to say things like "I know the applescript interface needs a complete overhaul but I don't want to break existing scripts!". ALL applescripters prefer it if the scripting interface gets better, even if it breaks existing scripts. So: Do it wrong now, but be prepared to fundamentally improve it later. :)
Even Apple has some lousy terminology, for example in iTunes there is an updatePodcast and updateAllPodcasts command. This is just wrong, according to their own technote 2106 - pay particular attention to the section on naming rules.. They should have a podcast object and an update command, so that you could also do things like "delete every podcast whose name contains "Ann Coulter". ("Whose" clauses are one of the coolest features of appleScript!)

Creating a new email message using the default email program

How can I programatically open a new message window in the default email client (such as Outlook) using Windows API calls? I will need to include an attachment and would prefer to specify the default message body in 'rich text' (ie. not plain) format.
The ShellExecute solution is good for simple messages without attachments, but if you want more control over the process, you may try the MAPI; in particular, see the MAPISendMail function and the MapiMessage structure.
For even more complex needs, there's the extended MAPI, but I didn't find any documentation about it on the MSDN. However this seems to be a good wrapper around the extended MAPI.
I think you can do this using the ShellExecute. An attachment should be used as parameter: something like this but I don't remember for sure: "mailto:email#something?subject=subject&body=body&attachment=..."

Resources