Sending Mail via Hyperlink

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
 
B

Brock Allen

Is this what you're looking for? There might be a different parameter that
allows to initialize the body, but I'm not aware of it.

<a href="mailto:[email protected]?Subject=Hello">Email you</a>
 
I

Ian Kelly

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
 
G

gaidar

Idea is to call some client function in body onload procedure. Try to find
some information about running default mail clients trougth client-scripts.
 
I

Ian Kelly

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
 
B

Brock Allen

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>
 
S

spinthemoose

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
 
D

David Alpert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top