I posted the same question using c# but didn't receive any answer, so i am going to attempt to post the same question using VB
i am trying to create a transport agent that verifies the subject line of outgoing email is not empty, if it is then it adds 'kranichs jewelers' to the subject line. If it is not empty, it propercases the format of the outgoing email
the code i have in vb:
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.Exchange.Data.Transport
Imports Microsoft.Exchange.Data.Transport.Routing
Imports Microsoft.Exchange.Data.Transport.Smtp
Namespace mySubjectAgent
NotInheritable Class myRoutingFactory
Inherits RoutingAgentFactory
Public Overrides Function CreateAgent(ByVal server As SmtpServer) As RoutingAgent
Return New MyAgent
End Function
End Class
Public Class MyAgent
Inherits RoutingAgent
Private Sub MyEndOfDataHandler(ByVal source As SubmittedMessageEventSource, ByVal e As QueuedMessageEventArgs) Handles Me.OnSubmittedMessage
If e.MailItem.Message.Subject.Length = 0 Then
e.MailItem.Message.Subject = "Kranichs Jewelers"
Else
e.MailItem.Message.Subject = StrConv(e.MailItem.Message.Subject, VbStrConv.ProperCase)
End If
End Sub
End Class
End Namespace
the problem with the code is.. whenever i install this transport agent to the exchange server, the que freezes and no email leaves the server.
any help is appreciated
There's two things you can try to start out:
Check Chris Haas' suggestion above and either add a try/catch to deal with nulls, or specifically watch for it using something like this:
if e.mailitem isnot nothing andalso e.mailitem.message isnot nothing andalso e.mailitem.subject isnot nothing then
' Fix case
elseif e.mailitem isnot nothing andalso e.mailitem.mesasge isnot nothing then
' Subject isn't set, go ahead and set one.
end if
Remove the code that does anything and just add some dummy code to replace it (like Dim i as integer = 2) to make sure that Exchange isn't stalling out just by having a transport agent of any kind.