Move .DeleteAfterSubmit not working (outlook 98)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Any ideas why in the following the .DeleteAfterSubmit command does not work?

With itm
.SentOnBehalfOfName = emailaccountname
.To = UserSender
.Unread = True
.VotingResponse = ReasonCode
.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.Mileage = AuditInfo & "," & Date & " " & Time
.FlagRequest = ServerTime
.DeleteAfterSubmit = True
.Move
End With

The code still writes the moved message to the personal namespace delete
folder of the user running the vb6.0 application?
 
Why do you call Move? It is a function returning new item; the original
mesasge must be immediately relased, much less sent.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
I have an application that allows multiple users to work in several company
email accounts. When they select a message via my GUI interface work the
message and hit reply the message is sent and then certain audit tags
applied. The original message with the modifications then needs to be moved
to archive folders.

Thanks!
Ed
 
I am confused - if the message is only moved, not sent, what do you expect
DeleteAfterSubmit to do? It sure looks like you set the DeleteAfterSubmit on
the itm object (before you send it?) and then move that very same object.
More than that, Move takes a MAPIFolder as a parameter, but you are not
specifying one.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
..Move

should read .Move objFolderReply

I dont think .DeleteAfterSubmit = True is what I need. How do I keep a copy
of the message when moved from the company email account inbox to the company
account sent folder from being copied to the personal deleted items folder of
the associate who responded to the email. THanks for your help Dmitry

Ed
 
I see - so you are trying to save the message in a folder other than the
default Sent Items folder, right?
You can set the MAPIFolder.SaveSentMessageFolder to an instance of the
MAPIFolder to force Outlook to move the message there after it wassent, but
note that it must be in the same store as the message in question (in most
cases the default folder).
If the target folder is in a different store, you can set a custom property
only teh message before sending it, then track the MAPIFolder.Items.ItemAdd
event on teh SEnt Items fodler to grab the message after it was sent, check
if your custom prop is there, then explicitly move the message to the
appropriate folder.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
I call a move because I want the email, with its now applied audit tags,
moved from the inbox to the sent mail folder. Is there another way I can
accomplish this without a copy of the email being written to any other folder?

Above I issue a send command with DeleteAfterSubmit = true to send the
actual response to the customer. If I left the DeleteAfterSubmit = false it
writes a copy to the personal sent items folder of the handling agent.

So I just want to move the email from the inbox to the sent items folder of
the account in which the associates are currently working. If I issue a copy
command it writes to the specified sent items folder but leaves the email in
the inbox. If I then issue a delete command it writes a copy to the personal
deleted items folder for the associate who worked the email.

Thanks for your help with this!
Ed
 
Since you want the message to be moved to a different store, do use the
MAPIFolder.Items.ItemAdd
event on the Sent Items folder to grab the message after it was sent and
explicuitly move. But that must be done *after* the mesage is sent and moved
to the Sent Items folder.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
I do see what you are saying. I issue a send command earlier in the routine,
but on a newly created message that does not have all the audit information
appended to the properties of the outlook message. I do not want to send a
message with all the audit information back to the customer. Perhaps instead
of creating the new message I should use the current mailitem and then add
the tags later? I will include the entire routine so you can better see what
is occurring. Please remember this is an application in development and
sylistically the programming leaves a lot to be desired. At the moment I
jsut want to get it to work ... Ill go back later and remove the GoTo
statements etc. Thanks for your continuing help Dmitry.

----------------------------


Public Sub Reply_Click()

Dim LineNumber As Single
Dim InquiryReason As String
Dim ReasonCode As String
Dim AttachmentString As String
Dim insidecount As Integer
Dim LocalDeptValue As Integer
Dim Attachment As Outlook.Attachment
Dim EntryIDKeyArray() As String
Dim EmailSender, EmailSubject, EmailReceivedTime As String

ServerTime = ReturnServerTime
InquiryReason = EmailManageWindow.EmailReason.Text
If InquiryReason = "" Or IsNull(InquiryReason) Then
MsgBox ("Please select an inquiry type.")
Exit Sub
End If

UserSubject = EmailManageWindow.Subject.Text
UserDate = EmailManageWindow.DateSent.Text
UserSender = EmailManageWindow.Sender.Text
UserBody = EmailManageWindow.Body.Text

' If no EntryId key has been established this is a new message and not a
reply to an existing message

If EntryID = "" Then
GoTo NewEmailSend
End If
Set itms = objFolder.Items
itms.SetColumns ("[Subject],[SenderName],[ReceivedTime],[Mileage]")

EntryIDKeyArray() = Split(EntryID, "#$%^")
EmailSender = EntryIDKeyArray(1)
EmailSubject = EntryIDKeyArray(2)
EmailReceivedTime = EntryIDKeyArray(3)
sFilter = "[SenderName] = '" & Replace(EmailSender, "'", "''") & "' And
[Subject] = '" & Replace(EmailSubject, "'", "''") & "'"
Set itm = itms.Find(sFilter)
Do While Not itm Is Nothing

' Because setting colums removes the seconds portion of the Recieved Time
have to make one final check to determine if this is the correct email

If itm.ReceivedTime = EmailReceivedTime Then
GoTo FoundItem:
End If
Set itm = itms.FindNext
Loop

If itm Is Nothing Then
For Each itm In itms
'MsgBox (itm.Subject)
If TypeName(itm) = "MailItem" Then
If InStr(1, itm.Subject, EmailSubject) > 0 Or itm.Subject = EmailSubject Then
' MsgBox (itm.SenderName)

If itm.SenderName = EmailSender Then
If itm.ReceivedTime = EmailReceivedTime Then
'MsgBox (itm.Unread)
GoTo FoundItem:
End If
End If
End If
End If

Next
GoTo NoItemFound:
End If
FoundItem:




If SpecificEmail = "" Or IsNull(SpecificEmail) Then
SpecificEmail = emailaccountname
End If
On Error GoTo ErrorFound:
If InStr(1, UserSender, "@") Then
GlobalFrom = UserSender
End If


' Find the numeric code associated with the subject and disposition of the
email for later reporting.

CommandText = "Select Department from tblEmailReason WHERE reason='" &
Replace(InquiryReason, "'", "''") & "' AND (MailBox IS Null OR MailBox<1 OR
MailBox=" & MailBoxID & ")"

Set cmd = New ADODB.Command
With cmd
.CommandText = CommandText
.CommandType = adCmdText
.CommandTimeout = 20
.ActiveConnection = ConnString
End With
Set rs = cmd.Execute
If Not rs.EOF And Not rs.BOF Then
LocalDeptValue = Trim(rs.Fields("Department").Value)
End If

CommandText = "Select reasoncode from tblEmailReason WHERE Active=1 AND
Department=" & LocalDeptValue & " AND reason='" & Replace(InquiryReason, "'",
"''") & "' AND (MailBox IS Null OR MailBox<1 OR MailBox=" & MailBoxID & ")"
Set cmd = New ADODB.Command
With cmd
.CommandText = CommandText
.CommandType = adCmdText
.CommandTimeout = 20
.ActiveConnection = ConnString
End With
Set rs = cmd.Execute
If Not rs.EOF And Not rs.BOF Then
ReasonCode = rs.Fields("reasoncode").Value
End If

' Add new item to be returned to the customer

Set objDummy = objFolder.Items.Add
For insidecount = 0 To EmailManageWindow.IncludedAttachmentsList.ListCount
AttachmentString =
EmailManageWindow.IncludedAttachmentsList.List(insidecount)
If AttachmentString <> "" And Not (IsNull(AttachmentString)) Then
Set Attachment = objDummy.Attachments.Add(AttachmentString, 1, ,
AttachmentString)
End If
Next


'Special Coding for Best Rate mailboxes
NewEmailSend:

Set cmd = New ADODB.Command
CommandText = "Select emailaccountname, OutEmail,outfolder from
tblEmailAccounts WHERE emailaccount='" & SpecificEmail & " '"

With cmd
.CommandText = CommandText
.CommandType = adCmdText
.CommandTimeout = 20
.ActiveConnection = ConnString
End With
Set rs = cmd.Execute
If Not rs.EOF And Not rs.BOF Then
SpecificEmailOut = rs.Fields("outfolder").Value
OutEmail = rs.Fields("OutEmail").Value
emailaccountname = rs.Fields("emailaccountname").Value

Else
GoTo NoOutFolderErr
End If

If OutEmail = "Best Rate" Then
objDummy.DeleteAfterSubmit = True

With objDummy
.SentOnBehalfOfName = "(e-mail address removed)"
.To = GlobalFrom
.Unread = True
.VotingResponse = ReasonCode
.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.Mileage = AuditInfo & "," & Date & " " & Time
If EmailManageWindow.CCTextBox.Text <> "" And Not
(IsNull(EmailManageWindow.CCTextBox.Text)) Then
.CC = EmailManageWindow.CCTextBox.Text
End If
If Trim(EmailManageWindow.BCCTextBox.Text) <> "" And Not
(IsNull(EmailManageWindow.BCCTextBox.Text)) Then
.BCC = EmailManageWindow.BCCTextBox.Text
End If
.DeleteAfterSubmit = True
.Send

End With

' End hard Coding for Best Rate mailbox"

Else


If GlobalFrom = "" Then
GlobalFrom = EmailManageWindow.Sender.Text
End If
If OutEmail = "" Then
OutEmail = EmailManageWindow.RenderedEmail.Text
End If

With objDummy
.SentOnBehalfOfName = OutEmail
.To = GlobalFrom
.Unread = True
If ReasonCode <> "" Then
.VotingResponse = ReasonCode
End If

.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.Mileage = AuditInfo & "," & Date & " " & Time
If EmailManageWindow.CCTextBox.Text <> "" And Not
(IsNull(EmailManageWindow.CCTextBox.Text)) Then
.CC = EmailManageWindow.CCTextBox.Text
End If
If Trim(EmailManageWindow.BCCTextBox.Text) <> "" And Not
(IsNull(EmailManageWindow.BCCTextBox.Text)) Then
.BCC = EmailManageWindow.BCCTextBox.Text
End If
.DeleteAfterSubmit = True
.Send
End With
End If

' Special Hard Coded Processing For Best Rate mailbox"
If emailaccountname = "Best Rate" Then
If ReasonCode = 140 Or ReasonCode = 141 Or ReasonCode = 142 Then
Set oMAPI = GetObject("", "Outlook.application").GetNamespace("MAPI")
Set oParentFolder = oMAPI.Folders("Mailbox - Best Rate Yes")
Set objFolder = oParentFolder.Folders.Item("Inbox")
Set objDummy = objFolder.Items.Add
objDummy.DeleteAfterSubmit = True

With objDummy
.Sender = GlobalFrom
.To = "(e-mail address removed)"
.Unread = True
.VotingResponse = ReasonCode
.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.Mileage = AuditInfo & "," & Date & " " & Time
If EmailManageWindow.CCTextBox.Text <> "" And Not
(IsNull(EmailManageWindow.CCTextBox.Text)) Then
.CC = EmailManageWindow.CCTextBox.Text
End If

If Trim(EmailManageWindow.BCCTextBox.Text) <> "" And Not
(IsNull(EmailManageWindow.BCCTextBox.Text)) Then
.BCC = EmailManageWindow.BCCTextBox.Text
End If
.FlagRequest = ServerTime
.DeleteAfterSubmit = True
.Send
End With
Else
Set oMAPI = GetObject("", "Outlook.application").GetNamespace("MAPI")
Set oParentFolder = oMAPI.Folders("Mailbox - Best Rate No")
Set objFolder = oParentFolder.Folders.Item("Inbox")
Set objDummy = objFolder.Items.Add

objDummy.DeleteAfterSubmit = True

With objDummy
.To = "(e-mail address removed)"
.Unread = True
.VotingResponse = ReasonCode
.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.DeleteAfterSubmit = True
.Mileage = AuditInfo & "," & Date & " " & Time
If EmailManageWindow.CCTextBox.Text <> "" And Not
(IsNull(EmailManageWindow.CCTextBox.Text)) Then
.CC = EmailManageWindow.CCTextBox.Text
End If
If Trim(EmailManageWindow.BCCTextBox.Text) <> "" And Not
(IsNull(EmailManageWindow.BCCTextBox.Text)) Then
.BCC = EmailManageWindow.BCCTextBox.Text
End If
.FlagRequest = ServerTime
.DeleteAfterSubmit = True
.Send
End With
End If
End If
Set oMAPI = GetObject("", "Outlook.application").GetNamespace("MAPI")
Set oParentFolder = oMAPI.Folders(SpecificEmail)
If oParentFolder.Folders.count Then
For insidecount = 1 To oParentFolder.Folders.count
If oParentFolder.Folders.Item(insidecount).Name = SpecificEmailOut Then
Set objFolderReply = oParentFolder.Folders.Item(insidecount)
inboxnumber = insidecount
GoTo FoundFolder
End If
Next
End If
FoundFolder:
If strname <> "" Then
Set objDummy = objApp.CreateItem(olMailItem)
Set objRecip = objNS.CreateRecipient(strname)
objRecip.Resolve
If objRecip.Resolved = True Then
On Error Resume Next
If objFolder Is Nothing Then
MsgBox "Cannot open '" + SpecificEmailOut + "' folder. Make
sure '" + objRecip.Name + "' has granted access.", , "Error"
Else
Dim found
found = False
countvariable = 0
End If
End If
End If

On Error Resume Next

If EntryID = "" Then
UserSender = EmailManageWindow.Sender.Text
UserBody = EmailManageWindow.Body.Text
UserSubject = EmailManageWindow.Subject.Text

With objDummy
.SentOnBehalfOfName = emailaccountname
.To = UserSender
.Unread = True
.VotingResponse = ReasonCode
.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.Mileage = AuditInfo & "," & Date & " " & Time
.FlagRequest = ServerTime

.Move objFolderReply
End With
Else
' MsgBox (UserDepartmentID)

With itm
.SentOnBehalfOfName = emailaccountname
.To = UserSender
.VotingResponse = ReasonCode
.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.Mileage = AuditInfo & "," & Date & " " & Time
.FlagRequest = ServerTime
.Unread = True
.Move objFolderReply
.DeleteAfterSubmit = True
End With

End If
EmailManageWindow.Hide
ManageAccounts True, "SpecificEmail", SpecificEmail, SubFolder
Exit Sub
NoItemFound:
Exit Sub
ErrorFound:
MsgBox ("The following error was encountered on line " & LineNumber & " : "
& Err.Description & vbCrLf & vbCrLf & "Source: " & Err.Source)
Exit Sub
NoOutFolderErr:
MsgBox ("No Sent Folder has been specified for this account. Please contact
a System Administrator")
End Sub
 
You should not touch the message in any way after Send is called; it must be
immediately released.
Send is an asynchronous process, by the time your code after Send runs, the
spooler/transport provider are still manipulating the message.
Again, the earliest you can access the sent message is in the
MAPIFolder.Items.ItemAdd event handler.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

emanson said:
I do see what you are saying. I issue a send command earlier in the
routine,
but on a newly created message that does not have all the audit
information
appended to the properties of the outlook message. I do not want to send
a
message with all the audit information back to the customer. Perhaps
instead
of creating the new message I should use the current mailitem and then add
the tags later? I will include the entire routine so you can better see
what
is occurring. Please remember this is an application in development and
sylistically the programming leaves a lot to be desired. At the moment I
jsut want to get it to work ... Ill go back later and remove the GoTo
statements etc. Thanks for your continuing help Dmitry.

----------------------------


Public Sub Reply_Click()

Dim LineNumber As Single
Dim InquiryReason As String
Dim ReasonCode As String
Dim AttachmentString As String
Dim insidecount As Integer
Dim LocalDeptValue As Integer
Dim Attachment As Outlook.Attachment
Dim EntryIDKeyArray() As String
Dim EmailSender, EmailSubject, EmailReceivedTime As String

ServerTime = ReturnServerTime
InquiryReason = EmailManageWindow.EmailReason.Text
If InquiryReason = "" Or IsNull(InquiryReason) Then
MsgBox ("Please select an inquiry type.")
Exit Sub
End If

UserSubject = EmailManageWindow.Subject.Text
UserDate = EmailManageWindow.DateSent.Text
UserSender = EmailManageWindow.Sender.Text
UserBody = EmailManageWindow.Body.Text

' If no EntryId key has been established this is a new message and not a
reply to an existing message

If EntryID = "" Then
GoTo NewEmailSend
End If
Set itms = objFolder.Items
itms.SetColumns ("[Subject],[SenderName],[ReceivedTime],[Mileage]")

EntryIDKeyArray() = Split(EntryID, "#$%^")
EmailSender = EntryIDKeyArray(1)
EmailSubject = EntryIDKeyArray(2)
EmailReceivedTime = EntryIDKeyArray(3)
sFilter = "[SenderName] = '" & Replace(EmailSender, "'", "''") & "' And
[Subject] = '" & Replace(EmailSubject, "'", "''") & "'"
Set itm = itms.Find(sFilter)
Do While Not itm Is Nothing

' Because setting colums removes the seconds portion of the Recieved Time
have to make one final check to determine if this is the correct email

If itm.ReceivedTime = EmailReceivedTime Then
GoTo FoundItem:
End If
Set itm = itms.FindNext
Loop

If itm Is Nothing Then
For Each itm In itms
'MsgBox (itm.Subject)
If TypeName(itm) = "MailItem" Then
If InStr(1, itm.Subject, EmailSubject) > 0 Or itm.Subject = EmailSubject
Then
' MsgBox (itm.SenderName)

If itm.SenderName = EmailSender Then
If itm.ReceivedTime = EmailReceivedTime Then
'MsgBox (itm.Unread)
GoTo FoundItem:
End If
End If
End If
End If

Next
GoTo NoItemFound:
End If
FoundItem:




If SpecificEmail = "" Or IsNull(SpecificEmail) Then
SpecificEmail = emailaccountname
End If
On Error GoTo ErrorFound:
If InStr(1, UserSender, "@") Then
GlobalFrom = UserSender
End If


' Find the numeric code associated with the subject and disposition of the
email for later reporting.

CommandText = "Select Department from tblEmailReason WHERE reason='" &
Replace(InquiryReason, "'", "''") & "' AND (MailBox IS Null OR MailBox<1
OR
MailBox=" & MailBoxID & ")"

Set cmd = New ADODB.Command
With cmd
.CommandText = CommandText
.CommandType = adCmdText
.CommandTimeout = 20
.ActiveConnection = ConnString
End With
Set rs = cmd.Execute
If Not rs.EOF And Not rs.BOF Then
LocalDeptValue = Trim(rs.Fields("Department").Value)
End If

CommandText = "Select reasoncode from tblEmailReason WHERE Active=1 AND
Department=" & LocalDeptValue & " AND reason='" & Replace(InquiryReason,
"'",
"''") & "' AND (MailBox IS Null OR MailBox<1 OR MailBox=" & MailBoxID &
")"
Set cmd = New ADODB.Command
With cmd
.CommandText = CommandText
.CommandType = adCmdText
.CommandTimeout = 20
.ActiveConnection = ConnString
End With
Set rs = cmd.Execute
If Not rs.EOF And Not rs.BOF Then
ReasonCode = rs.Fields("reasoncode").Value
End If

' Add new item to be returned to the customer

Set objDummy = objFolder.Items.Add
For insidecount = 0 To
EmailManageWindow.IncludedAttachmentsList.ListCount
AttachmentString =
EmailManageWindow.IncludedAttachmentsList.List(insidecount)
If AttachmentString <> "" And Not (IsNull(AttachmentString)) Then
Set Attachment = objDummy.Attachments.Add(AttachmentString, 1, ,
AttachmentString)
End If
Next


'Special Coding for Best Rate mailboxes
NewEmailSend:

Set cmd = New ADODB.Command
CommandText = "Select emailaccountname, OutEmail,outfolder from
tblEmailAccounts WHERE emailaccount='" & SpecificEmail & " '"

With cmd
.CommandText = CommandText
.CommandType = adCmdText
.CommandTimeout = 20
.ActiveConnection = ConnString
End With
Set rs = cmd.Execute
If Not rs.EOF And Not rs.BOF Then
SpecificEmailOut = rs.Fields("outfolder").Value
OutEmail = rs.Fields("OutEmail").Value
emailaccountname = rs.Fields("emailaccountname").Value

Else
GoTo NoOutFolderErr
End If

If OutEmail = "Best Rate" Then
objDummy.DeleteAfterSubmit = True

With objDummy
.SentOnBehalfOfName = "(e-mail address removed)"
.To = GlobalFrom
.Unread = True
.VotingResponse = ReasonCode
.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.Mileage = AuditInfo & "," & Date & " " & Time
If EmailManageWindow.CCTextBox.Text <> "" And Not
(IsNull(EmailManageWindow.CCTextBox.Text)) Then
.CC = EmailManageWindow.CCTextBox.Text
End If
If Trim(EmailManageWindow.BCCTextBox.Text) <> "" And Not
(IsNull(EmailManageWindow.BCCTextBox.Text)) Then
.BCC = EmailManageWindow.BCCTextBox.Text
End If
.DeleteAfterSubmit = True
.Send

End With

' End hard Coding for Best Rate mailbox"

Else


If GlobalFrom = "" Then
GlobalFrom = EmailManageWindow.Sender.Text
End If
If OutEmail = "" Then
OutEmail = EmailManageWindow.RenderedEmail.Text
End If

With objDummy
.SentOnBehalfOfName = OutEmail
.To = GlobalFrom
.Unread = True
If ReasonCode <> "" Then
.VotingResponse = ReasonCode
End If

.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.Mileage = AuditInfo & "," & Date & " " & Time
If EmailManageWindow.CCTextBox.Text <> "" And Not
(IsNull(EmailManageWindow.CCTextBox.Text)) Then
.CC = EmailManageWindow.CCTextBox.Text
End If
If Trim(EmailManageWindow.BCCTextBox.Text) <> "" And Not
(IsNull(EmailManageWindow.BCCTextBox.Text)) Then
.BCC = EmailManageWindow.BCCTextBox.Text
End If
.DeleteAfterSubmit = True
.Send
End With
End If

' Special Hard Coded Processing For Best Rate mailbox"
If emailaccountname = "Best Rate" Then
If ReasonCode = 140 Or ReasonCode = 141 Or ReasonCode = 142 Then
Set oMAPI = GetObject("", "Outlook.application").GetNamespace("MAPI")
Set oParentFolder = oMAPI.Folders("Mailbox - Best Rate Yes")
Set objFolder = oParentFolder.Folders.Item("Inbox")
Set objDummy = objFolder.Items.Add
objDummy.DeleteAfterSubmit = True

With objDummy
.Sender = GlobalFrom
.To = "(e-mail address removed)"
.Unread = True
.VotingResponse = ReasonCode
.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.Mileage = AuditInfo & "," & Date & " " & Time
If EmailManageWindow.CCTextBox.Text <> "" And Not
(IsNull(EmailManageWindow.CCTextBox.Text)) Then
.CC = EmailManageWindow.CCTextBox.Text
End If

If Trim(EmailManageWindow.BCCTextBox.Text) <> "" And Not
(IsNull(EmailManageWindow.BCCTextBox.Text)) Then
.BCC = EmailManageWindow.BCCTextBox.Text
End If
.FlagRequest = ServerTime
.DeleteAfterSubmit = True
.Send
End With
Else
Set oMAPI = GetObject("", "Outlook.application").GetNamespace("MAPI")
Set oParentFolder = oMAPI.Folders("Mailbox - Best Rate No")
Set objFolder = oParentFolder.Folders.Item("Inbox")
Set objDummy = objFolder.Items.Add

objDummy.DeleteAfterSubmit = True

With objDummy
.To = "(e-mail address removed)"
.Unread = True
.VotingResponse = ReasonCode
.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.DeleteAfterSubmit = True
.Mileage = AuditInfo & "," & Date & " " & Time
If EmailManageWindow.CCTextBox.Text <> "" And Not
(IsNull(EmailManageWindow.CCTextBox.Text)) Then
.CC = EmailManageWindow.CCTextBox.Text
End If
If Trim(EmailManageWindow.BCCTextBox.Text) <> "" And Not
(IsNull(EmailManageWindow.BCCTextBox.Text)) Then
.BCC = EmailManageWindow.BCCTextBox.Text
End If
.FlagRequest = ServerTime
.DeleteAfterSubmit = True
.Send
End With
End If
End If
Set oMAPI = GetObject("", "Outlook.application").GetNamespace("MAPI")
Set oParentFolder = oMAPI.Folders(SpecificEmail)
If oParentFolder.Folders.count Then
For insidecount = 1 To oParentFolder.Folders.count
If oParentFolder.Folders.Item(insidecount).Name = SpecificEmailOut Then
Set objFolderReply = oParentFolder.Folders.Item(insidecount)
inboxnumber = insidecount
GoTo FoundFolder
End If
Next
End If
FoundFolder:
If strname <> "" Then
Set objDummy = objApp.CreateItem(olMailItem)
Set objRecip = objNS.CreateRecipient(strname)
objRecip.Resolve
If objRecip.Resolved = True Then
On Error Resume Next
If objFolder Is Nothing Then
MsgBox "Cannot open '" + SpecificEmailOut + "' folder. Make
sure '" + objRecip.Name + "' has granted access.", , "Error"
Else
Dim found
found = False
countvariable = 0
End If
End If
End If

On Error Resume Next

If EntryID = "" Then
UserSender = EmailManageWindow.Sender.Text
UserBody = EmailManageWindow.Body.Text
UserSubject = EmailManageWindow.Subject.Text

With objDummy
.SentOnBehalfOfName = emailaccountname
.To = UserSender
.Unread = True
.VotingResponse = ReasonCode
.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.Mileage = AuditInfo & "," & Date & " " & Time
.FlagRequest = ServerTime

.Move objFolderReply
End With
Else
' MsgBox (UserDepartmentID)

With itm
.SentOnBehalfOfName = emailaccountname
.To = UserSender
.VotingResponse = ReasonCode
.Body = UserBody
.Subject = UserSubject
.RemoteStatus = AgentCode
.Mileage = AuditInfo & "," & Date & " " & Time
.FlagRequest = ServerTime
.Unread = True
.Move objFolderReply
.DeleteAfterSubmit = True
End With

End If
EmailManageWindow.Hide
ManageAccounts True, "SpecificEmail", SpecificEmail, SubFolder
Exit Sub
NoItemFound:
Exit Sub
ErrorFound:
MsgBox ("The following error was encountered on line " & LineNumber & " :
"
& Err.Description & vbCrLf & vbCrLf & "Source: " & Err.Source)
Exit Sub
NoOutFolderErr:
MsgBox ("No Sent Folder has been specified for this account. Please
contact
a System Administrator")
End Sub



Dmitry Streblechenko said:
Since you want the message to be moved to a different store, do use the
MAPIFolder.Items.ItemAdd
event on the Sent Items folder to grab the message after it was sent and
explicuitly move. But that must be done *after* the mesage is sent and
moved
to the Sent Items folder.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top