我有一个用于阅读从MS Outlook规则触发的电子邮件正文的宏。
每封电子邮件均已阅读但电子邮件来自Microsoft Outlook'这是MS Exchange服务器发送的传递失败邮件。
我需要阅读此项目以获取导致退回的电子邮件ID。
Sub VBS_GetEmailFromBodyText(anItem AsOutlook.MailItem)
'Email parameters
fromID = anItem.SenderName
toList = anItem.To
emailsubject = anItem.Subject
emailBody = Left(anItem.Body, 10)
receiveTime = anItem.ReceivedTime
'create query String
sqlQuery = "INSERT INTO [myDB].[dbo].[VBStestTable](fromID,toList,emailsubject,emailBody,receiveTime) Values('"& fromID & "','"& toList & "','"& emailsubject & "','"& emailBody & "','"& receiveTime & "')"
'SQL connection code
'------------------------
ConstadOpenStatic = 3
ConstadLockOptimistic = 3
objConnection = CreateObject("ADODB.Connection")
objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open( _
"Provider = SQLOLEDB; "& _
"Data Source=MyServer;"& _
"Trusted_Connection=Yes;"& _
"InitialCatalog=MyDB;"& _
"User ID=myUser;Password=myPassword;")
'-------------------------
'ended SQL Connection code
'RUN SQL Query --Insert records into DB
objRecordSet.Open(sqlQuery, _
objConnection, adOpenStatic, adLockOptimistic)
' Close the DB Connection
objConnection.Close()
EndSub
答案 0 :(得分:0)
您现在使用什么代码来阅读和解析邮件正文?
Outlook对象模型提供了三种使用项主体的主要方法:
您可以在Chapter 17: Working with Item Bodies中详细了解所有这些方式。我们取决于你选择阅读邮件正文的方式。