Sending Mail via Hyperlink

  • Thread starter Thread starter Ian Kelly
  • Start date Start date
I

Ian Kelly

Hi All,
Does anyone know how to execute a hyperlink programically? I need to create
and send an email message, but I need to have the default mail editor loaded
and populated with the message details and then have the user click on send.
'Mailto:' would work great if I could get it to fire automatically without
the user having to click on a link.

Any ideas?

Thanks
Ian
 
Hi,
Sorry I wasn't clear. I know how to for the URL for the mailto, I just
don't know how to get .NET to execute a hyperlink without someone actually
having to click on it.

Thanks
Ian
 
Idea is to call some client function in body onload procedure. Try to find
some information about running default mail clients trougth client-scripts.
 
Hi All,
First thanks for all the help. I just can not seem to get this to work. I
need to dynamically create the mailto url (no problem there). Then I need
to execute that url from the click event of a button as well as doing other
things. I have been pouring over the online help, but am getting nowhere.
Is it possible to execute a javascript function from the click event of a
button and pass it parameters? Is there a way to launch the default mail
program on the clients machine?

Thanks
Ian
 
Is it possible to execute a javascript function from the click event
of a button and pass it parameters?
Is there a way to launch the default mail program on the clients machine?

Yes; Here's one more try that does both. If this isn't what you want, then
I'm at a loss. Sorry.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script language="javascript">
function SendMail(to, subject, body)
{
window.open("mailto:" + to + "?subject=" + subject + "&body="
+ body);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" onclick="SendMail('(e-mail address removed)', 'hello',
'some body')" value="Send Mail To Brock" />
</form>
</body>
</html>

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
Can you not just use the format suggested earlier:
<script language="javascript">
function Foo()
{
window.open("mailto:[email protected]?subject=...");
}
</script>

In the button's click handler:

a) build the mailto url dynamically with a stringbuilder or
string.format()

b) build a dummy javascript function to wrap it, as in the above
example

c) use RegisterScript (or RegisterBlock, or RegisterScriptBlock..
havn't done this in a while) to write the script to your html page on
postback

d) programatically grab a reference to the page's body tag and add an
"onload" attribute that fires your dummy function
 
spinthemoose said:
c) use RegisterScript (or RegisterBlock, or RegisterScriptBlock..
havn't done this in a while) to write the script to your html page on
postback

"Insert the script block programmatically. To do this, use either the
Page.RegisterStartupScript() or the Page.RegisterClientScriptBlock()
method. In the first case, the JavaScript code will execute
immediately the next time the page is posted back. In the latter case,
the JavaScript code will not execute unless you connect the
client-side event of another control to the JavaScript function. In
this article, we'll use the first approach."
- http://www.ondotnet.com/pub/a/dotnet/2003/09/15/aspnet.html
 
Back
Top