Imports Outlook Partial Class _Default Inherits System.Web.UI.Page Private Sub cmdSend_Click(sender As Object, e As EventArgs) Handles cmdSend.Click ' Create Outlook App and Connect Dim OutlookApplication As New Application() ' create the MailItem which we want to send ' Use a try catch to make sure Outlook is running Try Dim email As MailItem = DirectCast(OutlookApplication.CreateItem(OlItemType.olMailItem), MailItem) ' Add a recipient for the email email.Recipients.Add("firstname.lastname@example.org") 'email.BodyFormat = OlBodyFormat.olFormatHTML email.HTMLBody = True email.Subject = "Test" email.Body = "This is a test <strong>email</strong><br/ >This is another line to check <i>outlook</i> email sending code" ' add display name, position and attach type for the attachment Dim DisplayName As String = "MyAttachment" Dim iPosition As Integer = email.Body.Length + 1 Dim AttachType As Integer = DirectCast(OlAttachmentType.olByValue, Integer) 'now attached the file 'Dim Attach As Attachment = email.Attachments.Add("C:\test.txt", AttachType, iPosition, DisplayName) ' open to read it first email.Display(True) ' Or just send 'email.Send() Catch End Try End Sub End Class
Gain unlimited access to on-demand training courses with an Experts Exchange subscription.Get Access
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE
Connect with Certified Experts to gain insight and support on specific technology challenges including: