Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to change email body in a newly created exchange.data.transport.email.emailmessage

Posted on 2014-12-16
3
Medium Priority
?
50 Views
Last Modified: 2016-06-14
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(BodyFormat.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("RejectedMessage", "message/rfc822")
                    Attach.EmbeddedMessage = AttachEmail.MailItem.Message
                End If
                Dim file As FileStream = New FileStream(reg_SERVER_PICKUP_DIR & FileName & ".eml", FileMode.Create)
                newEmail.MimeDocument.WriteTo(file)
                file.Close()
            Catch e As Exception
                WriteEventLog(e, ErrLevel)
            End Try
        End Sub
0
Comment
Question by:PetrosValsamis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Accepted Solution

by:
PetrosValsamis earned 0 total points
ID: 40504304
solved by my self:

Added the following lines to replace the newemail.body = Thebody :

                Dim newEmail As EmailMessage = EmailMessage.Create(BodyFormat.Html)
                Dim NewBody As Stream = newEmail.Body.GetContentWriteStream()
                NewBody.Write(System.Text.Encoding.Unicode.GetBytes(theBody), 0, Len(theBody))
                NewBody.Flush()
                NewBody.Close()
0
 
LVL 43

Expert Comment

by:Rob
ID: 41652507
Object - cleanup mistake
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data‚Ķ
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question