none
Send mail from outlook using a VB application RRS feed

  • General discussion

  • Hi Everyone,

    I am new to VB and I am still learning. I am using Visual Studio 2010. I have to create an application, where in users have to provide some details about the PO. I need to know how can I link this tool to Outlook so that when the user click the submit button, it fetches all the data from the text boxes and add those into a fresh email and send it out to a group of people? I have only the code for sending the mail, but i need the codes for fetching the data and picking an attachment from the app field.

    This is the code which i have right now.

    OutlookApp = CreateObject("Outlook.Application")
            OutlookMail = OutlookApp.CreateItem(Outlookmailitem)

            OutlookMail.To = "123@345.com"
            OutlookMail.Subject = "Project Status"
            OutlookMail.Body = "This is VB email test"

            If Len(MailAttach) = 0 Then
                OutlookMail.Attachments.Add("C:\ProjectStatus.xls")
            End If

            OutlookMail.Display()      'To display the email
            OutlookMail.Send()         'To send the email

            OutlookApp = Nothing
            OutlookMail = Nothing

    Please help. Any help is greatly appreciated.

    Tuesday, August 7, 2012 8:39 PM

All replies

  • What data do you want to get and where do you want to put it in the email?
     
    The best place to learn the basics of Outlook programming, with lots of samples available, is at www.outlookcode.com
     

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "agnath" <=?utf-8?B?YWduYXRo?=> wrote in message news:d610b29d-07db-417e-8852-9ae2088dea5b...

    Hi Everyone,

    I am new to VB and I am still learning. I am using Visual Studio 2010. I have to create an application, where in users have to provide some details about the PO. I need to know how can I link this tool to Outlook so that when the user click the submit button, it fetches all the data from the text boxes and add those into a fresh email and send it out to a group of people? I have only the code for sending the mail, but i need the codes for fetching the data and picking an attachment from the app field.

    This is the code which i have right now.

    OutlookApp = CreateObject("Outlook.Application")
            OutlookMail = OutlookApp.CreateItem(Outlookmailitem)

            OutlookMail.To = "123@345.com"
            OutlookMail.Subject = "Project Status"
            OutlookMail.Body = "This is VB email test"

            If Len(MailAttach) = 0 Then
                OutlookMail.Attachments.Add("C:\ProjectStatus.xls")
            End If

            OutlookMail.Display()      'To display the email
            OutlookMail.Send()         'To send the email

            OutlookApp = Nothing
            OutlookMail = Nothing

    Please help. Any help is greatly appreciated.


    Ken Slovak MVP - Outlook
    Wednesday, August 8, 2012 2:44 PM
    Moderator
  • Hi Agnath,

    Thank you for posting in the MSDN Forum.

    > I have to create an application, where in users have to provide some details about the PO. I need to know how can I link this tool to Outlook
    Suppose your application is a Windows Forms Application. In your project, if you want to use Outlook Objects you can add reference to Microsoft.Office.Interop.Outlook.

    > I need the codes for fetching the data and picking an attachment from the app field.
    In the application, suppose you have a textbox named textbox_MailTo to hold the Email address of the recipients, then you can use OutlookMail.To = textbox_MailTo.Text to pass the Email address to Outlook. The same goes for attachment, you could get the full name of your file and then pass it as a parameter to Attachments.Add method.

    Hope it helps.

    Best regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, August 9, 2012 6:39 AM
    Moderator