Auto Attach File to email
Sivakatirswami
katir at hindu.org
Fri Jan 27 17:02:58 EST 2006
Auto creation of emails from within my "remote tool box apps" which
send information with respect to the project (auto extract data from
some field and poke into the email) back to home base, is obviously
useful.
Now what I would like to add to this model is the ability to attach a
document... in particular a screen shot, to that email. (though I
supposed any document could be plugged in...) Program flow -
algorithm would go something like this:
put "/user/documents/tempPix.gif" into tTempScreenShot
export snapshot to file tTempScreenShot -- displays crosshairs to
select area
put "Question on this Word" into tSubject
put fwGestalt() into tbody # get all kind of sys info
put cr & cr & fld "whatever" after tBody
put cr & cr & "Comments: " after tBody
# I'm just guessing at this point:
put url "/User/Documents/somepath/screenShot.gig" into tAttachFilePath
revGoURL ("mailto:katir at hindu.org?subject=" & tSubject & "&body=" &
tBody & [attach= tAttachFilePath])
Again, in the parameters for revGoURL above, I'm just guessing
delete file tTempScreenShot
----------
Solution needs to be cross platform- mac windows... any ideas?
I could do this with applescript, but most of my users are on Windows...
One could also use another model for this which would be to post all
the data to our linux web server and have a CGI handle the mail and
the attachment... by using Sendmail cmds, but this is an added
"application layer" one tries to avoid.
Then there is the option to post just the file to the internet serve
and put the http://mysever/path/screenShot.jpg" link in the email,
but this fragments the response. (screen shot is not actually visible
in the email that discusses the issues...)
But, if revGoURL's limitations are such...
Sivakatirswami
I see lots of refs to this on the net but this one is troubling,
though perhaps very old, indicating that "Outlook" will not handle a
simple path parameter to a doc.
============
However, you commonly see code trying to use mailto like this:
mailto:shiver at metimbers.com?Subject=Ahoy there
shipmate&Body=Here's the shipping
manifest&Attach="D:\manifest.doc"
It probably won't attach the document because you are at the liberty
of the email client to implement the mailto protocol and include
parsing for the attachment clause. You may not know what mail client
is installed on the PC, so it may not always work - Outlook certainly
doesn't support attachments using mailto.
==========
but there is this C code option, but I don't think ther eis a simple
way to add a C code chunk to a rev script on the fly
If your customers are using Outlook or Outlook Express as their email
client, then you can use the MailTo comamnd with a little help. Here
is the C# code I use to programmatically add attachments to emails.
string filename = openFileDialog1.FileName;
// look at the registry mailto command to determine the default email
client
RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"mailto\shell\open
\command");
if (key != null)
{
// look for Outlook
string mailto_command = (string) key.GetValue("");
if (mailto_command.ToLower().IndexOf("outlook.exe") > 0)
{
// execute mailto: command
string execute = @"mailto:?";
System.Diagnostics.Process.Start(execute);
// delay 1/2 second so that the email client can open
Thread.Sleep(500);
// send keys to add file as an attachment
SendKeys.Send("%(if)" + filename + "{TAB}{TAB}{ENTER}");
}
// look for Outlook Express
else if (mailto_command.ToLower().IndexOf("msimn") > 0)
{
// execute mailto: command
string execute = @"mailto:?";
System.Diagnostics.Process.Start(execute);
// delay 1/2 second so that the email client can open
Thread.Sleep(500);
// send keys to add file as an attachment
SendKeys.Send("%ia" + filename + "{TAB}{TAB}{ENTER}");
}
else // unsupported email client
{
// tell user only Outlook and Outlook Express are supported
MessageBox.Show("The MailTo button only works with Outlook and
Outlook Express", "Your default email client is not supported",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
else // unsupported email client
{
// tell user only Outlook and Outlook Express are supported
MessageBox.Show("The MailTo button only works with Outlook and
Outlook Express", "Your default email client is not supported",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
Curt
More information about the use-livecode
mailing list