Link to home
Start Free TrialLog in
Avatar of sana khan
sana khanFlag for India

asked on

On Button click outlook will open and the link generated will be copied to outlook

When a user clicks the button an outlook  will open and the link generated will be copied to outlook  email message..Can you help me for this in asp.net

Below is the file related to this issue is attached with it.LinkGeneration.txt
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

You can try use the onclientclick event.

<asp:Button ID="btnRedirect" CssClass="form-submit-button" 
                  Text=" Copy to Outlook" runat="server" onclientclick="email(this.form.txtLink.value);return false;" />

Open in new window


then try add this into your HTML:

<script>
    function email(URL) {
        document.location.href = "mailto:test@example.com?subject=subject&body=" + URL;
    }
</script>

Open in new window

Javascript popups are sometimes disabled on different machines/browsers which will prevent the javascript code from executing. You can try this server side in C# as well.

using System.Diagnostics;

 protected void btnRedirect_Click(object sender, EventArgs e)
        {

            var myUrl = "mailto:someone@somewhere.com?subject=Test&body=" + txtLink.Text;
            Process.Start(myUrl);


            Response.Redirect(URL + "?" + getQueryString());
        }

Open in new window

Hi sana,

First add reference of ‘Microsoft.Office.Interop.Outlook’ library in your project. This code will run on any machines that contains Outlook locally.

Then add below lines of code to your .cs page.

protected void btnRedirect_Click(object sender, EventArgs e)
        {
            //Response.Redirect(URL + "?" + getQueryString());
            string Messagebody = URL + "?" + getQueryString();
            CreateMailItem(Messagebody);
        }

        private void CreateMailItem(string Messagebody)
        {
            Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.MailItem mailItem = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
            mailItem.Subject = "This is the test message";
            mailItem.To = "contactus@authorcode.com";
            mailItem.CC = "supporttools@authorcode.com";
            mailItem.Body = Messagebody;
            mailItem.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceNormal;
            mailItem.Display(false);
            mailItem = null;
            oApp = null;
        }

Open in new window


For more details please follow the link.

http://www.authorcode.com/how-to-create-outlook-email-item-using-c-and-vb-net/
Avatar of sana khan

ASKER

Actually i am working on server so how would i add reference of ‘Microsoft.Office.Interop.Outlook’ library in my project, because it is not showing
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial