none
compose email with visual studio (VB), automatically inserting email address and subject, then leave it to the user to complete RRS feed

  • Question

  • Hi I program in visual studio (VB), I want to automatically insert an email address and subject, then open up this new email for the user, who will then complete the rest and then sent it manually.

    Have tried the following. No new email message was found.

    Thanks

    Imports outlook = Microsoft.Office.Interop.Outlook
    Public Class Form1

        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click


            Dim OutlookMessage As outlook.MailItem
            Dim AppOutlook As New outlook.Application

            Dim objNS As outlook._NameSpace = AppOutlook.Session
            Dim objFolder As outlook.MAPIFolder
            objFolder = objNS.GetDefaultFolder(outlook.OlDefaultFolders.olFolderDrafts)

            Try
                OutlookMessage = AppOutlook.CreateItem(outlook.OlItemType.olMailItem)
                Dim Recipents As outlook.Recipients = OutlookMessage.Recipients
                Recipents.Add("myemail@hotmail.com")
                OutlookMessage.Subject = "Sending through Outlook"
            Catch ex As Exception
                MessageBox.Show("Mail could not be sent")
            Finally
                OutlookMessage = Nothing
                AppOutlook = Nothing
            End Try


        End Sub
    End Class

    • Moved by Neda Zhang Tuesday, November 8, 2016 8:24 AM moved from vb
    Tuesday, November 8, 2016 2:08 AM

Answers

  • Hi,

    You have to actually issue a Display command to show the email after composign it.

    Add OutlookMessage.Display() to you method to show the email as non-modal, or OutlookMessage.Display(true) to show it as modal.

    Tuesday, November 8, 2016 8:54 AM

All replies

  • Hi Paulnz123,

    Thank you for posting in MSDN Forum.

    Since your issue is more related to Outlook development , I will move this thread to the more related forum.

    Reference: https://social.msdn.microsoft.com/Forums/en-US/home?forum=outlookdev&filter=alltypes&sort=lastpostdesc

    Thanks for your understanding and support.

    Best Regards,

    Neda Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 8, 2016 8:21 AM
  • Hi,

    You have to actually issue a Display command to show the email after composign it.

    Add OutlookMessage.Display() to you method to show the email as non-modal, or OutlookMessage.Display(true) to show it as modal.

    Tuesday, November 8, 2016 8:54 AM
  • Hi Paulnz123,

    I agree with the suggestion given by the Koen Matthijs.

    I tested it and it is working as per your requirement.

    so I suggest you to implement the suggestion given by him to solve your issue.

    I suggest you to mark the suggestion given by the Koen Matthijs as an Answer.

    below is an updated code.

    Imports outlook = Microsoft.Office.Interop.Outlook
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim OutlookMessage As outlook.MailItem
            Dim AppOutlook As New outlook.Application
    
            Dim objNS As outlook._NameSpace = AppOutlook.Session
            Dim objFolder As outlook.MAPIFolder
            objFolder = objNS.GetDefaultFolder(outlook.OlDefaultFolders.olFolderDrafts)
    
            Try
                OutlookMessage = AppOutlook.CreateItem(outlook.OlItemType.olMailItem)
                Dim Recipents As outlook.Recipients = OutlookMessage.Recipients
                Recipents.Add("myemail@hotmail.com")
                OutlookMessage.Subject = "Sending through Outlook"
                OutlookMessage.Display()
            Catch ex As Exception
                MessageBox.Show("Mail could not be sent")
            Finally
                OutlookMessage = Nothing
                AppOutlook = Nothing
            End Try
    
    
        End Sub
    End Class
    

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 9, 2016 4:12 AM
    Moderator
  • Thank you, all of you for replying. I had been away and my problem had being solved by Koen Matthijs, thanks again

    regards

    Paul

    Thursday, November 10, 2016 6:41 PM