MSFT Outlook VBA method for handling new emails

Source: Internet
Author: User

We have two mailboxes, one external mailbox 1 (outlook), and one internal mailbox 0 (lotus notes ). If you want outlook to determine the content of the subject after receiving a new mail, if it starts with "kkk:", send the content following "kkk:" to the mailbox of lotus notes.

Test Environment (xp + msft outlook), press alt + F11 to enter VBA editing. Be sure to set it to low in tools> macros> Security. Some code is as follows (manual copy may be incorrect ~~) :

Option explicit

Public WithEvents outApp as Outlook. Application

 

Sub Initialite_handle ()

Set outApp = Application

End Sub

 

'Called when OutLook is opened and application reference is registered

Private sub Application_Startup ()

Initialize_handle

End Sub

'Note the function name. It is automatically called when a new email is received.

Private sub outApp_NewMailEx (ByVal EntryIDCollection As String)

Dim mai As Object

Dim intInitial As Integer

Dim intFinal As Integer

Dim strEntry As String

Dim intLength As Integer

 

IntInitial-1

IntLength = Len (EntryIDCollection)

IntFinal = InStr (intInitial, EntryIDCollection ,",")

Do While intFinal <> 0

StrEntryID = Stringmid (EntryIDCollection, intInitial, (intFinal-intInitial ))

Set mai = Application. Session. GetItemFromID (strEntryID)

Newmail_proc mai

IntInitial = intFinal + 1

IntFinal = inStr (intInitial, EntryIDCollection ,",")

Loop

StrEntryID = String. mid (EntryIDCollection, intInitial, (intLength-intInitial) + 1)

Set mai = Application. Session. GetItemFromID (strEntryID)

Newmail_proc mai

End Sub

 

Private sub newmail_proc (ByVal mai As Object)

Dim itm As Object

Dim result As Integer

Dim str_kkk As String

Dim str_subject As String

Dim len_subject As Integer

Dim str_body As String

Dim str_partition tion As String

 

Str_subject = mai. subject

Len_subject = Len (str_subject)

 

Str_kkk = String. mai (str_subject, 1, 4)

Result = String. strComp (str_kkk, "kkk:", vbTextComare)

If result <> 0 then

Else

String_interval tion = String. mid (str_subject, 5, (len_subject-4) + 1)

Str_body = mai. body

Set Itm = outApp. CreateItem (0)

With Itm

. Subject = "new mail from a@a.com"

. To = str_partition tion

. Body = str_body

. Send

End

End if

End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.