none
How to send email by ribbon button RRS feed

  • Question

  • Hello,

    i trying to send email by custom Ribbon Button 

    so plese tell me how to get send email by this button and  get body  of mail in in Ribbon button

    thanks


    Dharmesh Sharma info@dharmeshsharma.com www.dharmeshsharma.com

    Tuesday, March 26, 2013 8:56 PM

All replies

  • Hi Dharmesh,

    Fistly, get EmailItem and get body of email. you can use the below code snippets to get selected mail body:

    private string body()
    { 
        Outlook.Application myApplication =        Globals.ThisAddIn.Application;
        Outlook.Explorer myActiveExplorer = (Outlook.Explorer)myApplication.ActiveExplorer();
    
         Outlook.Selection selection = myActiveExplorer.Selection;
    
         if (selection.Count == 1 && selection[1] is Outlook.MailItem)
         {
              Outlook.MailItem mail = (Outlook.MailItem)selection[1];
    
    return mail.Body;
         }
    }

    Then in the click event of Ribbon button, you can call MailItem.Send() method to send the email:

    private void sendEmai_click(object sender, RibbonControlEventArgs e)
    {
        mail.send()
    }

    Thanks.

    Wednesday, March 27, 2013 3:23 AM
  • hello Learning hard

    I want to send new mail not selected mail

    i have no idea how to send a new mail which is type by me and i want to send this mail by my button 

    i hope you got it

    thanks


    Dharmesh Sharma info@dharmeshsharma.com www.dharmeshsharma.com

    Thursday, March 28, 2013 4:55 PM
  • Your code can reference the ActiveInspector() object, which is the open item with focus. Get Inspector.CurrentItem for that ActiveInspector(), cast it to a MailItem and call the item's Send() method to send the item.
     
    An alternative would be to handle Inspectors.NewInspector() when an item is opened. Set up event handling for that Inspector's Activate() event. In that event get Inspector.CurrentItem, cast it to a Mailitem and hold a reference to that item. When your button is clicked, call the Send() method on the item.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Dharmesh sharma" <=?utf-8?B?RGhhcm1lc2ggc2hhcm1h?=> wrote in message news:1c7b7241-a8a4-427a-8e99-3e15c5d3d672...

    hello Learning hard

    I want to send new mail not selected mail

    i have no idea how to send a new mail which is type by me and i want to send this mail by my button 

    i hope you got it

    thanks


    Dharmesh Sharma info@dharmeshsharma.com www.dharmeshsharma.com


    Ken Slovak MVP - Outlook
    Thursday, March 28, 2013 5:11 PM
    Moderator
  • Hi Dharmesh,

    Your requirement is easy, you can use Outlook.Application.CreateItem method create MailItem and Initialize the subject, to, body property, then you can call MailItem.Send method to send a new mail,  you can refer to the msdn Article and you can insert those codes snippet into the click event of your button.

    Thanks.

    • Proposed as answer by Learning hard Friday, March 29, 2013 2:48 AM
    Friday, March 29, 2013 2:48 AM
  • hello Learning hard

    yes i am using this concept of msdn but i am trying to get mail body , send to email list from outlook (which is compose a mail) then send 

    so i am not get the compose body and send to email list

    i hope you got it 

    thanks


    Dharmesh Sharma info@dharmeshsharma.com www.dharmeshsharma.com

    Saturday, March 30, 2013 5:13 AM
  • You set Outlook.MailItem.To property to a string which including emali list. and what is meaning about compose body? can you give a screenshot to explain compose body?

    If you solve the problem, you can help to show the codes here.

    Thanks a lot



    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample

    Wednesday, April 17, 2013 2:38 AM
  • Hello

    see in pic what i want

    i wan to send emial with "fabsend it" button

    this main conect what i want to make for outllok

    so please give me idea or code so i can do and make some more stuff


    Dharmesh Sharma info@dharmeshsharma.com www.dharmeshsharma.com

    Wednesday, April 17, 2013 7:38 AM
  • You have create MailItem object, so you can get property(including To Property, body and so on) from the current MailItem.

    For how to get MailItem from the customer Ribbon, you can refer to below article:

    Overview of the IRibbonControl Object

    After you get the MailItem object from your ribbon, you can access the property and Call the Send method of the MailItem to send email in your "fabsend it" button click event.

    You can get some code snippets from the link.

    I hope those can help you. Thanks


    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample

    Wednesday, April 17, 2013 8:28 AM