Send a mail using invoke code

Dim _app As Microsoft.Office.Interop.Outlook._Application=Nothing
Dim mail As Microsoft.Office.Interop.Outlook.MailItem=Nothing
_app=New Microsoft.Office.Interop.Outlook.ApplicationClass()

mail=CType(_app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem),Microsoft.Office.Interop.Outlook.MailItem)

mail.To=“your id”
mail.Subject=“TEest”
mail.Body=“robo test”
mail.Attachments.Add(“d:\test.xlsx”)
mail.Attachments.Add(“d:\sanj.xlsx”)
mail.Attachments.Add(“d:\Test_Modified_path.zip”)

mail.Importance=Microsoft.Office.Interop.Outlook.OlImportance.olImportanceNormal
CType(mail,Microsoft.Office.Interop.Outlook.MailItem).Send()

1 Like

Hello!

Nice :slight_smile:

Could you share the use case for this since we have the Send Email activities?

image

Regards,

1 Like

The main use case I can see if the ability to add attachments at run time. So for example you can read the contents of a folder and attach all the files found.
Using the Send Mail activities you cannot dynamically add attachments.

Did you ever get this to work? I’m still getting the error:

No compiled code to run
error BC30512: Option Strict On disallows implicit conversions from ‘Object’ to ‘Microsoft.Office.Interop.Outlook.MailItem’.