Hi,
Not really certain if this is the correct forum or not. My apologies if not. I'm creating a VS.NET 2005 application using VB.NET. I've downloaded and installed the Visual Studio Tools for Office 2005 as well as the code snippets.
What I want to do is send an email. I'm getting my feet a little wet before jumping right in!
My code is as follows:
Dim mailItem As Outlook.MailItem = Me.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)mailItem.Subject =
"Email Subject" 'TODO: Change the Subject field of the e-mail item.mailItem.Body = "Email Body" 'TODO: Change the body of the e-mail item.
mailItem.To = "myemail@work.com" 'TODO: Change the recipient's address.
mailItem.Display(False) 'True to make the window modal. The default value is False.
mailItem.Send()
I've included Microsoft Office 11.0 Object Library
Microsoft Outlook 11.0 Object Library
Microsoft.Office.Tools.Outlook
Microsoft.VisualStudio.Tools.Applications.Runtime References
The error message I'm getting is:
Error 1 'CreateItem' is not a member of 'CustAdmin.frmCustomerLookup'.
Any help is appreciated.
Thanks

Sending Emails ..
Steven43126
John,
Thank you so much for the reply. Very helpful indeed. I'll take a look at the resources you've outlined.
-- Val
Zephyr_Yi
I was having a the same problem, but I am wondering if there is a an alternative to CreateItem...
I should tell you that I am using the 2003.net Standard Edition which may not have all the bells and whistles of the professional...
Now here is what I want to do...
Public
Class Form1 Inherits System.Windows.Forms.Form#
Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer.InitializeComponent()
'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Thencomponents.Dispose()
End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Button1 As System.Windows.Forms.Button<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(80, 80) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 0 Me.Button1.Text = "Button1" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.Add(Me.Button1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub#
End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickAddContact()
End Sub Private Sub AddContact() Dim newContact As Outlook.ContactItem = Me.CreateItem(Outlook. _ ' The problem is in the CreateItem, I getting an a message that CreateItem is not a member of the Form1'OlItemType.olContactItem)
Try With newContact.FirstName = "Jo"
.LastName = "Berry"
.Email1Address = "somebody@example.com"
.CustomerID = "123456"
.PrimaryTelephoneNumber = "(425)555-0111"
.MailingAddressStreet = "123 Main St."
.MailingAddressCity = "Redmond"
.MailingAddressState = "WA"
.Save()
.Display(
True) End With CatchMessageBox.Show("The new contact was not saved.")
End Try End SubEnd
Class" I want to Send E-mail at the click of a button and also add contacts that way as well. I plan on making a program that can do MailMerge but with E-mail through Outlook.
If anyone can make it easy for me to get through this problem, I would appreciate it, just tell me what Extra code I need or what step...I will also try to look into resources that are available if I get the Time to.
Have a Fantastic Day!
Marc Young
If you have the snippets set up, there is one that will create mail items for you.
To "install" the snippets, you will need to add the installation directory to the snippet manager.
Goto Tools->Snippet Manager (Ctrl + K, Ctrl + B) and press add and then add the installation directory (C:\Program Files\Microsoft\VSTO - Outlook\Snippets\VB\OfficeDevelopment\Outlook by default).
In the editor, right click and choose "Insert Snippet", this will pop up an intellisense window, choose Outlook, Create,CreateMailItem
eosull41
I'm sorry you are having difficulty with your project. Your problem is pretty easy to fix, fortunately!
The clue to the issue is in the error message: .NET cannot find CreateItem in the definition of your form. When you use the Me keyword (or this in C#), it is going to use the current class definition for its context. In your code, you are attempting to use the CreateItem method in the context of your custom form. It isn't there. It's actually in the class definition of ThisApplication, a separate class which inherits from Microsoft.Office.Tools.Outlook.Application and is split between two class files.
Partial
Public NotInheritable Class ThisApplication Inherits Microsoft.Office.Tools.Outlook.Application...
End
ClassYou can only make a call to the methods of ThisApplication in the context of its instance lifetime. Your instance of frmCustomerLookup is not that context, as you have it. For example, if you were to do this, it will work:
public class ThisApplication
End Class
This will solve things for you. I recommend you look at the Outlook development resources I have listed here:
http://blogs.msdn.com/johnrdurant/archive/2005/12/07/vsto_outlook_resourcelist.aspx
Good luck!
John.