Link to home
Start Free TrialLog in
Avatar of nbtnotes
nbtnotesFlag for United States of America

asked on

Email Forward: Get Around Relay Issue

I created an agent that forwards selected emails to a particular email address. My problem is the code that does not work sends the email and is stopped by the mail server due to the fact the email is treated as a relay.

The code that does work removes a few fields from the email and allows the email to be forwarded.

I some how need to keep the original sender a part of the header. Is there a way for me to add an extra header called "X-Original-Recipient" to this email?

Does not Work
	Dim session As New NotesSession	
	Dim wsUI As New NotesUIWorkspace
	Dim dbCurrent As NotesDatabase, dbMailBox As NotesDatabase	
	Dim vwCurrent As NotesUIView	
	Dim dcCurrent As NotesDocumentCollection
	Dim docCurrent As NotesDocument, docMail As NotesDocument
	Dim itmMail As NotesItem
	Dim iPromptResponse As Integer
	
	Set dbCurrent = session.CurrentDatabase
	Set dbMailBox = New NotesDatabase(dbCurrent.Server, "mail.box")
	Set vwCurrent = wsUI.CurrentView
	Set dcCurrent = vwCurrent.Documents
	Set docCurrent = dcCurrent.GetFirstDocument
	While Not ( docCurrent Is Nothing )			
		Set docMail = New NotesDocument(dbMailBox)
		Call docCurrent.Copyallitems(docMail, True)
		docMail.Form = "Memo"
		docMail.PostedDate = Now
		docMail.SendTo = "JohnDoe@sentto.com"
		docMail.CopyTo = ""
		docMail.ReplyTo = "MyEmail@from.com"
		Call docMail.Removeitem("From")
		docMail.From = "CN=MyEmail/OU=usr/O=From"
		docMail.Principal = "CN=MyEmail/OU=usr/O=From"
		docMail.INETFrom = "MyEmail@from.com"
		docMail.Recipients = docMail.SendTo
		Call docMail.Save(True, False)
		
		Set docCurrent = dcCurrent.GetNextDocument( docCurrent )
	Wend
	
	Call vwCurrent.DeselectAll
	Call wsUI.ViewRefresh

Open in new window



Works
	Dim session As New NotesSession	
	Dim wsUI As New NotesUIWorkspace
	Dim dbCurrent As NotesDatabase, dbMailBox As NotesDatabase	
	Dim vwCurrent As NotesUIView	
	Dim dcCurrent As NotesDocumentCollection
	Dim docCurrent As NotesDocument, docMail As NotesDocument
	Dim itmMail As NotesItem
	Dim iPromptResponse As Integer
	
	Set dbCurrent = session.CurrentDatabase
	Set dbMailBox = New NotesDatabase(dbCurrent.Server, "mail.box")
	Set vwCurrent = wsUI.CurrentView
	Set dcCurrent = vwCurrent.Documents
	Set docCurrent = dcCurrent.GetFirstDocument
	While Not ( docCurrent Is Nothing )			
		Set docMail = New NotesDocument(dbMailBox)
		Call docCurrent.Copyallitems(docMail, True)
		docMail.Form = "Memo"
		docMail.PostedDate = Now
		docMail.SendTo = "JohnDoe@sentto.com"
		docMail.CopyTo = ""
		docMail.ReplyTo = "MyEmail@from.com"
		Call docMail.Removeitem("From")
		docMail.From = "CN=MyEmail/OU=usr/O=From"
		docMail.Principal = "CN=MyEmail/OU=usr/O=From"
		docMail.INETFrom = "MyEmail@from.com"
		docMail.Recipients = docMail.SendTo
		Call docMail.Removeitem("Received")
		Call docMail.Removeitem("$InetOrig")
		Call docMail.Removeitem("SMTPOriginator")
		Call docMail.Removeitem("SpamS_Direction")
		Call docMail.Removeitem("CWeSigProcessed")
		Call docMail.Removeitem("$Orig")
		Call docMail.Removeitem("DeliveredDate")
		Call docMail.Save(True, False)
		
		Set docCurrent = dcCurrent.GetNextDocument( docCurrent )
	Wend
	
	Call vwCurrent.DeselectAll
	Call wsUI.ViewRefresh

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of nbtnotes
nbtnotes
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nbtnotes

ASKER

Determined MIME was the best route and realized I needed to remove CopyAllItems to make it work.
Avatar of Steve Knight
Has this bookmarked to look today as saw it on the way out for weekend and clearly you fixed anyway.  Interesting way of doing it that I hadn't done, have used various ways to get around different issues over the years when needed.

Only thing I'd suggest is mark the email in some way (e.g. subject line) and check for that as part of your routine as otherwise all you need is an auto-responder / dodgy out of the office / bounce message and you end up with nasty loop and rapidly filled server.