[用件]
受信したメールのフォーマットをText形式に変更し、添付ファイルを削除して転送したい
[実現方法の概要]
MailItem オブジェクトの BodyFormat プロパティを TEXT形式に変更する
MailItem オブジェクトの Forward メソッドにより 転送用の MailItem オブジェクトを生成する
MailItem オブジェクトの Attachments プロパティにより Attachments オブジェクトを取得する
Attachments オブジェクトの Count を Removeメソッドによって減ずる
[注意点]
電子メール アドレスを指定する行には、メッセージの転送先の電子メール アドレスを指定します
その他の注意点については、下記参照のこと
http://support.microsoft.com/kb/292063/ja
[記述例]
Public WithEvents myOlItems As Outlook.Items
Public Sub Application_Startup()
' Reference the items in the Inbox.
' Because myOlItems is declared "WithEvents" the ItemAdd event will fire below.
Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub myOlItems_ItemAdd(ByVal Item As Object)
' Check to make sure it is an Outlook mail message, otherwise
' subsequent code will probably fail depending on what type of item it is.
If TypeName(Item) = "MailItem" Then
' Translate the format into plain text
Item.BodyFormat = olFormatPlain
' Forward the item just received
Set myForward = Item.Forward
' Remove Attachments
Set myAttachments = myForward.Attachments
While myAttachments.Count > 0
myAttachments.Remove 1
Wend
' Address the message
myForward.Recipients.Add "myaddress@mydomain.com"
' Send it
myForward.Send
End If
End Sub
|