PetrosValsamis
asked on
How to change email body in a newly created exchange.data.transport.email.emailmessage
I had created an exchange transport agent for manipulating incoming email to our exchange 2010 server.
One of its functions is to alert some users, by email, for an email received under specific conditions. So i wrote a code that creates a new email message and saves it in the Pickup folder of the "transportroles", which is working perfectly. However I can not find the way to add/change the body of it since it is read only.
Here is the code:
Public Sub SaveEmailForSend(ByVal FromEmail As String, ByVal TheSubject As String, ByVal theBody As String, ByVal ToEmails As String, Optional ByVal CCEmails As String = "", Optional ByVal BccEmails As String = "", Optional ByVal AttachEmail As EndOfDataEventArgs = Nothing, Optional ByVal FileName As String = "NewEmailToSend")
Dim newEmail As EmailMessage = EmailMessage.Create(BodyFo rmat.Html)
Try
newEmail.From = New EmailRecipient("", FromEmail)
newEmail.Subject = TheSubject
' HERE IS THE PROBLEM
newEmail.body = TheBody
' end of HERE IS THE PROBLEM
If Not ToEmails Is Nothing Then
For Each ToRec In Split(ToEmails, ";")
newEmail.To.Add(New EmailRecipient("", ToRec))
Next
End If
If Not CCEmails Is Nothing Then
For Each CCRec In Split(CCEmails, ";")
newEmail.Cc.Add(New EmailRecipient("", CCRec))
Next
End If
If Not BccEmails Is Nothing Then
For Each bccRec In Split(BccEmails, ";")
newEmail.Bcc.Add(New EmailRecipient("", bccRec))
Next
End If
If Not AttachEmail Is Nothing Then
Dim Attach As Attachment = newEmail.Attachments.Add(" RejectedMe ssage", "message/rfc822")
Attach.EmbeddedMessage = AttachEmail.MailItem.Messa ge
End If
Dim file As FileStream = New FileStream(reg_SERVER_PICK UP_DIR & FileName & ".eml", FileMode.Create)
newEmail.MimeDocument.Writ eTo(file)
file.Close()
Catch e As Exception
WriteEventLog(e, ErrLevel)
End Try
End Sub
One of its functions is to alert some users, by email, for an email received under specific conditions. So i wrote a code that creates a new email message and saves it in the Pickup folder of the "transportroles", which is working perfectly. However I can not find the way to add/change the body of it since it is read only.
Here is the code:
Public Sub SaveEmailForSend(ByVal FromEmail As String, ByVal TheSubject As String, ByVal theBody As String, ByVal ToEmails As String, Optional ByVal CCEmails As String = "", Optional ByVal BccEmails As String = "", Optional ByVal AttachEmail As EndOfDataEventArgs = Nothing, Optional ByVal FileName As String = "NewEmailToSend")
Dim newEmail As EmailMessage = EmailMessage.Create(BodyFo
Try
newEmail.From = New EmailRecipient("", FromEmail)
newEmail.Subject = TheSubject
' HERE IS THE PROBLEM
newEmail.body = TheBody
' end of HERE IS THE PROBLEM
If Not ToEmails Is Nothing Then
For Each ToRec In Split(ToEmails, ";")
newEmail.To.Add(New EmailRecipient("", ToRec))
Next
End If
If Not CCEmails Is Nothing Then
For Each CCRec In Split(CCEmails, ";")
newEmail.Cc.Add(New EmailRecipient("", CCRec))
Next
End If
If Not BccEmails Is Nothing Then
For Each bccRec In Split(BccEmails, ";")
newEmail.Bcc.Add(New EmailRecipient("", bccRec))
Next
End If
If Not AttachEmail Is Nothing Then
Dim Attach As Attachment = newEmail.Attachments.Add("
Attach.EmbeddedMessage = AttachEmail.MailItem.Messa
End If
Dim file As FileStream = New FileStream(reg_SERVER_PICK
newEmail.MimeDocument.Writ
file.Close()
Catch e As Exception
WriteEventLog(e, ErrLevel)
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Object - cleanup mistake