Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim outEmail As Outlook.MailItem
Dim savePath As String
If Item.Class = OlObjectClass.olMail Then
savePath = "c:\temp\test.msg"
Set outEmail = Item
outEmail.SaveAs savePath, olMsg
End If
Dim strProgramName As String
strProgramName = "C:\myProgram\EmailImportClient.exe"
Call Shell("""" & strProgramName & """", vbNormalFocus)
Imports System.IO
Imports Microsoft.Office
Imports Outlook = Microsoft.Office.Interop.Outlook
Public Class EmailImport
Public fromemailaddress As String
Private Sub EmailImport_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ImportEmails()
Me.Close()
End Sub
Private Sub ImportEmails()
Dim OL As Outlook.Application = CreateObject("Outlook.Application")
Dim item2 As Outlook.MailItem = CType(OL.CreateItemFromTemplate("c:\temp\test.msg", Type.Missing), Outlook.MailItem)
fromemailaddress = GetSenderSMTPAddress(item2)
End Sub
Private Function GetSenderSMTPAddress(mail As Outlook.MailItem) As String
Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
If mail Is Nothing Then
Throw New ArgumentNullException()
End If
If mail.SenderEmailType = "EX" Then
Dim sender As Outlook.AddressEntry = mail.Sender
If sender IsNot Nothing Then
If sender.AddressEntryUserType = Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry OrElse sender.AddressEntryUserType = Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry Then
Dim exchUser As Outlook.ExchangeUser = sender.GetExchangeUser()
If exchUser IsNot Nothing Then
Return exchUser.PrimarySmtpAddress
Else
Return Nothing
End If
Else
Return TryCast(sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS), String)
End If
Else
Return Nothing
End If
Else
Return mail.SenderEmailAddress
End If
End Function
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.