Friday, March 16, 2012

Open client email software "in front" of ASP page and not behind it

I have a push button on an aspx page that causes a new and partially empty email message to be created using the client machine's email software. This is accomplished through the following statement in the "clicked" method for the button:

System.Diagnostics.

Process.Start("mailto:" + sbTo.ToString() +"?subject=TestSubject&body=TestBody");

The code executes correctly on postback. The problem is that the email message window is in the background, behind my aspx page, so the only way I can tell the message window is open is to observe its icon on the Windows task bar. I'm using Outlook Express but I don't think that is material to this point.

I want the email message window to be in the foreground and in front of my aspx page. How can I force the email window to the foreground from my codebehind method?

Thanks!

I believe that if you simply create a hyperlink with the mailto in it, then the client email app will launch and take focus

Thanks for your reply. I agree that a hyperlink can be used to open the client email software and I use that technique at times.

However, in this case I need to perform some server-side processing to generate a list of email addresses that are to receive the email. It may be one or it may be many addresses that are needed in the "To" field - that is what I am determining in the "click" method for the button. So I'm stuck with my approach, I believe, and I need a way to force the focus to the Outlook Express window so that it is displayed on top of my aspx page. (Everything is working properly, this is simply a display issue with the email window in the background.) The problem seems to be that the Outlook Express new message window is opened and then my aspx page is rendered, causing the aspx page to conceal the email window.

The only alternative to this that I see would be to use JavaScript on the client side to perform the logic that now is in the "click" method for the push button. I'm not sure how I would accomplish that. I would need JavaScript logic to examine every item in a DataList and I don't know how to do that. Has anyone got a JavaScript code fragment?

Thanks!

BCB


I think the problem isn't the window appearing behind the web page but rather the client being initiated before the postback, then the postback brings the focus back to the web browser. Instead of in the OnClick can you launch this in a Page IsPostback?

Jeff


Oops! I misunderstood what I was doing. I was trying to open the email software on the client machine but I now see that what I was doing would open the client software on the server, and that is not what I want.

So I'm in a deeper hole than I thought.

What is the best way to generate a "To" list of email addresses and then open the client's email software and create a message with the "To" line prepopulated with the values that I constructed programmatically in the "click" method on the server side? Would something like RegisterStartupScript be advisable?

Thanks for any and all ideas.


How about sending a mailto link with the proper info? Otherwise, look at some of the Office Automation tools for .NET, this is probably in there.

Jeff


Jeff,

I'm not sure what you mean by "sending a mailto link". Can you break it down a little more for me?

Thanks!

0 comments:

Post a Comment