![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hi,
I wish to divert all my mails that come from User A to users B & C. Also while diverting, i need to check if the filename from 'A' is in mht format, i wish to change the extension that to .xls & send to B & C. Is this possible in VBA ? i am using Microsoft outlook 2003(11.8118.8132) SP2 Thanks, |
Ads |
#2
|
|||
|
|||
![]()
All that is possible:
- use the MAPIFolder.Items.ItemAdd to trap incoming mails - use MailItem.SenderName or MailItem.SenderEmailAddress to determine whether this is "User A" - use MailItem.Attachments to inspect all Attachment.FileName properties for the extension you're looking for - use Attachment.SaveAsFile to save it to disk, then use the Name statement to rename it - use MailItem.Attachments.Remove and MailItem.Attachments.Add to replace the attachment, then MailItem.Save to commit your changes - use MailItem.Forward to redirect to other users - use MailItem.Recipients.Add to add the other users - call MailItem.Send All examples above are using the actual object names for reference purposes - use variables to create instances of these objects with your code. -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "chits" wrote: Hi, I wish to divert all my mails that come from User A to users B & C. Also while diverting, i need to check if the filename from 'A' is in mht format, i wish to change the extension that to .xls & send to B & C. Is this possible in VBA ? i am using Microsoft outlook 2003(11.8118.8132) SP2 Thanks, |
#3
|
|||
|
|||
![]()
Thanks for this logic.. i tried implementing this protocol... but i am not
able to trap the address at run time... I have the following code embedded in the outlook session Can you please help me in correcting if anything is not initialised / incorrect? Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) If TypeOf Item Is Outlook.MailItem Then Cancel = Not SendBigMail(Item) End If End Sub Private Function SendBigMail(oMail As Outlook.MailItem) As Boolean Dim lSize As Long Dim bSend As Boolean Dim FileName As String Dim TAtt As Long Dim l As Long Const MIN_SIZE As Long = 50000 oMail.Save bSend = True If oMail.SenderEmailAddress = " Then TAtt = oMail.Attachments.count 'Total number of attachments in my mail If TAtt 0 Then l = 1 For l = 1 To TAtt lSize = oMail.Size If (Right(oMail.Attachments.Item(l).FileName, 3) = "mht") Or (Right(oMail.Attachments.Item(l).FileName, 3) = "xls") Or (Right(oMail.Attachments.Item(l).FileName, 3) = "pdf") Then If lSize MIN_SIZE Then oMail.To = "Chitra Bhatia" oMail.Subject = "Blank report Check " & oMail.Subject ' If its a blank attachment then send me a notification mail SendBigMail = bSend Exit Function End If ' Change the .mht file to xls before sending If Right(oMail.Attachments.Item(l).FileName, 3) = "mht" Then FileName = Replace(oMail.Attachments.Item(l).FileName, "mht", "xls", 1, 3) oMail.Attachments.Item(l).SaveAsFile FileName Set oMail.Attachments.Item(l) = oMail.Attachments.Add(FileName, olByValue) End If End If Next For l = 1 To TAtt If Right(oMail.Attachments.Item(l).FileName, 3) = "mht" Then oMail.Attachments.Item(l).Delete l = l - 1 End If Next End If End If SendBigMail = bSend End Function "Eric Legault [MVP - Outlook]" wrote: All that is possible: - use the MAPIFolder.Items.ItemAdd to trap incoming mails - use MailItem.SenderName or MailItem.SenderEmailAddress to determine whether this is "User A" - use MailItem.Attachments to inspect all Attachment.FileName properties for the extension you're looking for - use Attachment.SaveAsFile to save it to disk, then use the Name statement to rename it - use MailItem.Attachments.Remove and MailItem.Attachments.Add to replace the attachment, then MailItem.Save to commit your changes - use MailItem.Forward to redirect to other users - use MailItem.Recipients.Add to add the other users - call MailItem.Send All examples above are using the actual object names for reference purposes - use variables to create instances of these objects with your code. -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "chits" wrote: Hi, I wish to divert all my mails that come from User A to users B & C. Also while diverting, i need to check if the filename from 'A' is in mht format, i wish to change the extension that to .xls & send to B & C. Is this possible in VBA ? i am using Microsoft outlook 2003(11.8118.8132) SP2 Thanks, |
#4
|
|||
|
|||
![]()
Wrong event! Item_Send captures *outgoing* e-mail, not incoming. Below is
some sample code that illustrates how to trap incoming e-mail. Option Explicit Private WithEvents NewMailItems As Outlook.Items Private Sub Application_Quit() Set NewMailItems = Nothing End Sub Private Sub Application_Startup() Set NewMailItems = Application.GetNamespace("MAPI").GetDefaultFolder( olFolderInbox).Items End Sub Private Sub NewMailItems_ItemAdd(ByVal Item As Object) 'THIS WILL FIRE FOR EVERY NEW E-MAIL; YOU CAN USE THE 'Item OBJECT TO WORK WITH THE PROPERTIES OF THE E-MAIL MESSAGE Dim objMail As Outlook.MailItem If Item.Class olmail Then Exit Sub Set objMail = Item objMail.UnRead = False objMail.FlagStatus = olNoFlag End Sub -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "chits" wrote: Thanks for this logic.. i tried implementing this protocol... but i am not able to trap the address at run time... I have the following code embedded in the outlook session Can you please help me in correcting if anything is not initialised / incorrect? Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) If TypeOf Item Is Outlook.MailItem Then Cancel = Not SendBigMail(Item) End If End Sub Private Function SendBigMail(oMail As Outlook.MailItem) As Boolean Dim lSize As Long Dim bSend As Boolean Dim FileName As String Dim TAtt As Long Dim l As Long Const MIN_SIZE As Long = 50000 oMail.Save bSend = True If oMail.SenderEmailAddress = " Then TAtt = oMail.Attachments.count 'Total number of attachments in my mail If TAtt 0 Then l = 1 For l = 1 To TAtt lSize = oMail.Size If (Right(oMail.Attachments.Item(l).FileName, 3) = "mht") Or (Right(oMail.Attachments.Item(l).FileName, 3) = "xls") Or (Right(oMail.Attachments.Item(l).FileName, 3) = "pdf") Then If lSize MIN_SIZE Then oMail.To = "Chitra Bhatia" oMail.Subject = "Blank report Check " & oMail.Subject ' If its a blank attachment then send me a notification mail SendBigMail = bSend Exit Function End If ' Change the .mht file to xls before sending If Right(oMail.Attachments.Item(l).FileName, 3) = "mht" Then FileName = Replace(oMail.Attachments.Item(l).FileName, "mht", "xls", 1, 3) oMail.Attachments.Item(l).SaveAsFile FileName Set oMail.Attachments.Item(l) = oMail.Attachments.Add(FileName, olByValue) End If End If Next For l = 1 To TAtt If Right(oMail.Attachments.Item(l).FileName, 3) = "mht" Then oMail.Attachments.Item(l).Delete l = l - 1 End If Next End If End If SendBigMail = bSend End Function "Eric Legault [MVP - Outlook]" wrote: All that is possible: - use the MAPIFolder.Items.ItemAdd to trap incoming mails - use MailItem.SenderName or MailItem.SenderEmailAddress to determine whether this is "User A" - use MailItem.Attachments to inspect all Attachment.FileName properties for the extension you're looking for - use Attachment.SaveAsFile to save it to disk, then use the Name statement to rename it - use MailItem.Attachments.Remove and MailItem.Attachments.Add to replace the attachment, then MailItem.Save to commit your changes - use MailItem.Forward to redirect to other users - use MailItem.Recipients.Add to add the other users - call MailItem.Send All examples above are using the actual object names for reference purposes - use variables to create instances of these objects with your code. -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "chits" wrote: Hi, I wish to divert all my mails that come from User A to users B & C. Also while diverting, i need to check if the filename from 'A' is in mht format, i wish to change the extension that to .xls & send to B & C. Is this possible in VBA ? i am using Microsoft outlook 2003(11.8118.8132) SP2 Thanks, |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Divert outlook mails after changing attachments | chits | Outlook - Installation | 0 | July 3rd 07 02:56 PM |
OE is changing unread e-mails to read | Helen | Outlook Express | 9 | November 4th 06 04:02 PM |
is it possible to divert sent mail into different folders? | Alias | Outlook Express | 8 | August 21st 06 04:20 PM |
Incoming e-mails are showing up as an attachment also | Dazzler | Outlook - General Queries | 1 | May 2nd 06 03:19 PM |
Rule to filter e-mails with a specific text string in an attachment | [email protected] | Outlook - General Queries | 2 | April 19th 06 10:38 AM |