Torna al Thread

Imports Outlook = Microsoft.Office.Interop.Outlook Public Class Form1 Private Account As Outlook.Account Private olApp As Outlook.Application Private olSession As Outlook.NameSpace Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub LoadAccount() Dim olAccounts As Outlook.Accounts olApp = New Outlook.Application() olSession = olApp.Session olAccounts = olSession.Accounts For Each elemento As Outlook.Account In olAccounts Console.WriteLine(elemento.DisplayName) Next 'Account = olSession.Accounts(0) Account = olSession.Accounts(1) End Sub Private Sub SendOutlookMail_3(ByVal Subject As String, ByVal Recipient As String, ByVal Message As String, Optional ByVal CC As String = "") LoadAccount() Dim item As Outlook.MailItem item = olApp.CreateItem(Outlook.OlItemType.olMailItem) item.SendUsingAccount = Account item.Subject = Subject item.Body = Message item.Recipients.Add(Recipient) item.Recipients.ResolveAll() item.Send() End Sub Private Sub SendOutlookMail_2(ByVal Subject As String, ByVal Recipient As String, ByVal Message As String, ByVal Originator As String, Optional ByVal CC As String = "") 'Reference Or here is GAC path C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Outlook\14.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Outlook.dll Dim Outlook As New Microsoft.Office.Interop.Outlook.Application Dim MailItem As Microsoft.Office.Interop.Outlook.MailItem MailItem = Outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) With MailItem .HTMLBody = Message .Subject = Subject 'use the below to change from the default email account .SentOnBehalfOfName = Originator 'you can add multiple recipients using .Add() .Recipients.Add(Recipient) 'examples of other optional arguments that can be included .Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh .Display() 'opens the email for checking prior to sending or use .Send() End With End Sub 'Non serve referenziare la libreria Microsoft.Office.Interop.Outlook.dll Private Sub SendOutlookMail(ByVal Subject As String, ByVal Recipient As String, ByVal Message As String, ByVal Originator As String, Optional ByVal CC As String = "") On Error GoTo errorHandler Dim oLapp As Object Dim oItem As Object oLapp = CreateObject("Outlook.application") oItem = oLapp.createitem(0) ' With oItem .Subject = Subject .SentOnBehalfOfName = Originator .To = Recipient .body = Message .CC = CC .Send() End With ' oLapp = Nothing oItem = Nothing ' Exit Sub errorHandler: oLapp = Nothing oItem = Nothing MessageBox.Show("Notification failed; check that all addresses/entries are valid and try again.", "Task failure (Outlook).", MessageBoxButtons.OK, MessageBoxIcon.Stop) Exit Sub End Sub End Class
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5