We help IT Professionals succeed at work.

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

sana khan
sana khan asked
on
264 Views
Last Modified: 2017-11-04
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
Comment
Watch Question

Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:
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

Commented:
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

Tapan PattanaikSenior Engineer

Commented:
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/

Author

Commented:
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
Software Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.