MailTo Question

R

Rob Edwards

I have an Asp.net application that we use to track changes to our Servers...
Up to this point I have been using Web.Mail to send messages using an SMTP
server. The users would like to have the mail route through Outlook so 1)
They can edit the message and 2) The message is stored in their Sent Items.

The simpliest method would appear to be automating a MailTo link... such as

Response.Redirect(mailto:[email protected]?subject=Test&body=This%20is%20a%20Text)

The problem is that this routes the client to a new blank window. It does
open their default email client, but the underlying page changes.

Is there any way to incorporate the mailto link into a script so I can
execute the code necessary to change the state of the Servers and display
the updated information on the same page once the email is sent?

Thanks in advance.
 
Y

Yama

Hello,

Here is how you would need to do this:

'-----------------------------------------------
' Write a javascript popup window event
'-----------------------------------------------
sRedirect = "mailto:[email protected]?subject=Test&body=This%20is%20a%20Text"
Private Sub OpenWindow(ByVal sRedirect As String)
' Script Header
Dim sReportViewerPageRequest As String = ""
' Open the window instance or reload the same
Dim sReportType As String = "Report"

sReportViewerPageRequest += "<script>"
sReportViewerPageRequest += "var hWnd = window.open(""" & sRedirect & """,""" & sReportType & _
""",""top=0,left=0,width=800,height=600,resizable=yes,"
sReportViewerPageRequest += "scrollbars=yes,toolbar=no,menubar=yes""); self.close();"
sReportViewerPageRequest += "</" + "script>"
'Execute Function
Response.Write(sReportViewerPageRequest)
End Sub


Hope this helps,

Yama
 
S

Steven Cheng[MSFT]

Thanks for Curt and Yama's good suggestions.

Hi Rod,

As for your questions, I think you may have a look at Yama's sample page
code which demonstrate the suggestion that write a "window.open" script to
client in code behind code.

In addtion, I've also another suggestion here:
Since generally we can open the default mail client via click a hyperlink
as below:
<a
href="mailto:[email protected]?subject=Test&amp;body=This%20is%20a%20Tex
t">MailTo</a>

So I think we can put a certain hyperlink on the page and set it as
invisiable ( using style="display:none"). Then register a clientside script
to fire the hyper link 's click event. Thus, we can also make the client
popup the default mail client and the underlying page is stll remaining. To
make it clearly, here is a demo page I've tested, please have a look to see
whether it helps:

----------------------------aspx page----------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>MailTo</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function doSendMail()
{
document.getElementById("lnkMailTo").click();
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table align="center" width="100%">
<tr>
<td>
<asp:Label id="lblMessage" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td><a id="lnkMailTo" style="display:none"
href="mailto:[email protected]?subject=Test&amp;body=This%20is%20a%20Tex
t">MailTo</a></td>
</tr>
<tr>
<td>
<asp:LinkButton id="btnSendMail" runat="server">Send
Mail</asp:LinkButton>
</td>
</tr>
</table>
</form>
</body>
</HTML>

------------------code behind page class--------------------
Public Class MailTo
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
Protected WithEvents btnSendMail As System.Web.UI.WebControls.LinkButton

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub btnSendMail_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSendMail.Click
Dim script As String = "<script
language='javascript'>doSendMail();</script>"
Page.RegisterStartupScript("sendmail", script)
lblMessage.Text = "Please Complete the Mail and Send it."
End Sub
End Class
----------------------------------------------


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
R

Rob Edwards

Whoever Yama is... you're a GOD.... I looked around for at least 2 or 3 hours trying to get info.....your solution is perfect.
Hello,

Here is how you would need to do this:

'-----------------------------------------------
' Write a javascript popup window event
'-----------------------------------------------
sRedirect = "mailto:[email protected]?subject=Test&body=This%20is%20a%20Text"
Private Sub OpenWindow(ByVal sRedirect As String)
' Script Header
Dim sReportViewerPageRequest As String = ""
' Open the window instance or reload the same
Dim sReportType As String = "Report"

sReportViewerPageRequest += "<script>"
sReportViewerPageRequest += "var hWnd = window.open(""" & sRedirect & """,""" & sReportType & _
""",""top=0,left=0,width=800,height=600,resizable=yes,"
sReportViewerPageRequest += "scrollbars=yes,toolbar=no,menubar=yes""); self.close();"
sReportViewerPageRequest += "</" + "script>"
'Execute Function
Response.Write(sReportViewerPageRequest)
End Sub


Hope this helps,

Yama
 
Y

Yama

Hello Rob,

I am merely only a human being and a mortal which I am very much pleased with. I take it that my solution helped you. It was my pleasure.

Yama
Whoever Yama is... you're a GOD.... I looked around for at least 2 or 3 hours trying to get info.....your solution is perfect.
Hello,

Here is how you would need to do this:

'-----------------------------------------------
' Write a javascript popup window event
'-----------------------------------------------
sRedirect = "mailto:[email protected]?subject=Test&body=This%20is%20a%20Text"
Private Sub OpenWindow(ByVal sRedirect As String)
' Script Header
Dim sReportViewerPageRequest As String = ""
' Open the window instance or reload the same
Dim sReportType As String = "Report"

sReportViewerPageRequest += "<script>"
sReportViewerPageRequest += "var hWnd = window.open(""" & sRedirect & """,""" & sReportType & _
""",""top=0,left=0,width=800,height=600,resizable=yes,"
sReportViewerPageRequest += "scrollbars=yes,toolbar=no,menubar=yes""); self.close();"
sReportViewerPageRequest += "</" + "script>"
'Execute Function
Response.Write(sReportViewerPageRequest)
End Sub


Hope this helps,

Yama
 

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

Top