Recently, I received a query from an ADN partner, as part of partner customisation requirement expects users to send feedback about publisher app.
The idea is to trigger outlook from a .NET command which is loaded in a macro button.
We can use Microsoft.Office.Interop.Outlook API to achieve this in our command.
Sample code:
Use assemblyref Microsoft.Office.Interop.Outlook
[CommandMethod("SMTP")]
static public void SMTP()
{
try
{
List<string> lstAllRecipients = new List<string>();
//Below is hardcoded - can be replaced with db data
lstAllRecipients.Add("[email protected]");
Outlook.Application outlookApp =
new Outlook.Application();
Outlook._MailItem oMailItem =
(Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector oInspector = oMailItem.GetInspector;
// Recipient
Outlook.Recipients oRecips =
(Outlook.Recipients)oMailItem.Recipients;
foreach (String recipient in lstAllRecipients)
{
Outlook.Recipient oRecip =
(Outlook.Recipient)oRecips.Add(recipient);
oRecip.Resolve();
}
//Add Subject
oMailItem.Subject = "Test Mail";
// body
oMailItem.Body = " Write your Body ";
//Display the mailbox
oMailItem.Display(true);
}
catch (SystemException objEx)
{
Application.ShowAlertDialog(objEx.ToString());
}
}
In the CUI macro button, pass ^C^C_SMTP
Reference:DisplayMailbox