Post

2 followers Follow
2
Avatar

Uploading email from Outlook

I have created an Outlook addon that uploads emails and attachments from within Outlook to a Work Item. The problem is that Clarizen lists the Sent By and Sent On as "System" and today's date, respectively. These fields are read only.

How do I get by this and have the Sent By be the email sender and the Sent On by the email date?

Thanks

Import from old forum Answered

Please sign in to leave a comment.

14 comments

0
Avatar

Hi Mark,

Indeed those fields are read only and are automatically captures the creation date of the respective entities in the system as well as the user under which it was created.

Can you describe a little more the outlook addon that you have developed? How are you sending those files and emails to Clarizen?

Rachel

Import from old forum 0 votes
Comment actions Permalink
0
Avatar

The short answer, it is much more robust than this:

 

I have created a ribbon addon that lists a users workitems. When they are in Outlook.Explorer they may select multiple items and then upload the items to Clarizen as email documents associated with the work item.

Here is the Upload code:

'-------------------------------------------------------------------------------------------------------

'Collect email information

Dim newMailNote As New StringBuilder

newMailNote.AppendLine("Date: " & mail.ReceivedTime)

newMailNote.AppendLine("From: " & mail.Sender.Name)

newMailNote.AppendLine("To: " & mail.To)

newMailNote.AppendLine("CC: " & mail.CC)

newMailNote.AppendLine("Subject: " & mail.Subject)

newMailNote.AppendLine("")

newMailNote.AppendLine(mail.HTMLBody)

'-------------------------------------------------------------------------------------------------------

'Create Connection

Dim cClient As ClarizenSrv.ClarizenClient = Login()

If IsNothing(cClient) Then

MsgBox("Logon Failure", MsgBoxStyle.SystemModal)

Exit Sub

End If

'-------------------------------------------------------------------------------------------------------

'Get user

Dim userID As New ClarizenSrv.EntityId

Dim UserFields As New ClarizenSrv.stringList

UserFields.Add("Email")

UserFields.Add("DisplayName")

Dim query As New ClarizenSrv.FindUserQuery

query.EMail = Mid(mail.Sender.Address, InStr(mail.Sender.Address, "cn=Recipients/cn=") + Len("cn=Recipients/cn=")) & "@sscoop.com"

query.IncludeSuspendedUsers = True

query.Permissions = ClarizenSrv.PermissionOptions.ObjectAndFields

query.Fields = UserFields

Dim queryUser As ClarizenSrv.QueryResult = cClient.Query(cSessionHeader, query)

If queryUser.Entities.Count = 1 Then

Dim newEmailSenderEntity As New ClarizenSrv.GenericEntity

For Each userEntity As ClarizenSrv.GenericEntity In queryUser.Entities

userID = userEntity.Id

Next

Else

'No User

End If

'-------------------------------------------------------------------------------------------------------

'This creates a Clarizen email for selected Project

Dim newEmail As New ClarizenSrv.GenericEntity

newEmail.Id = New ClarizenSrv.EntityId

newEmail.Id.TypeName = "Email"

Dim newEmailParent As New ClarizenSrv.FieldValue

newEmailParent.FieldName = "AttachedTo"

newEmailParent.Value = queryResult.Entities.ElementAt(ddIndex - 1).Id

Dim newEmailBody As New ClarizenSrv.FieldValue

newEmailBody.FieldName = "Comment"

newEmailBody.Value = newMailNote.ToString

Dim newEmailSubject As New ClarizenSrv.FieldValue

newEmailSubject.FieldName = "Subject"

newEmailSubject.Value = mail.Subject

'Dim newEmailDate As New ClarizenSrv.FieldValue

'newEmailDate.FieldName = "CreatedOn"

'newEmailDate.Value = DateTime.UtcNow

Dim newEmailFrom As New ClarizenSrv.FieldValue

newEmailFrom.FieldName = "SentBy"

newEmailFrom.Value = userID

'If IsNothing(userID) Then

newEmail.Values = New ClarizenSrv.FieldValue() {newEmailBody, newEmailSubject, newEmailParent}

'Else

' newEmail.Values = New ClarizenSrv.FieldValue() {newEmailBody, newEmailSubject, newEmailParent, newEmailFrom}

'End If

Dim createEmail As New ClarizenSrv.CreateMessage

createEmail.Entity = newEmail

'-------------------------------------------------------------------------------------------------------

'Upload email to Clarizen

Try

Dim newResults() As ClarizenSrv.Result = cClient.Execute(cSessionHeader, New ClarizenSrv.CallOptions, New ClarizenSrv.BaseMessage() {createEmail})

Dim resultInfo As ClarizenSrv.CreateResult = newResults(0)

If newResults(0).Success Then

newEmail.Id = resultInfo.Id

MsgBox("Uploaded Message.", MsgBoxStyle.SystemModal)

Else

MsgBox(newResults(0).Error, MsgBoxStyle.SystemModal)

Logout(cClient)

Exit Sub

End If

Catch ex As Exception

MsgBox("Failed to Upload Message.", MsgBoxStyle.SystemModal)

Logout(cClient)

Exit Sub

End Try

'-------------------------------------------------------------------------------------------------------

'Are there any attachments?

If mail.Attachments.Count > 0 Then

For Each attach As Outlook.Attachment In mail.Attachments

Dim path As String = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

Dim strExtention() As String = {"JPG", "PNG", "BMP", "GIF"}

If Not strExtention.Contains(UCase(Right(attach.FileName, 3))) Then

attach.SaveAsFile(path & "\" & attach.FileName)

Dim newAttach As New ClarizenSrv.GenericEntity

newAttach.Id = New ClarizenSrv.EntityId

newAttach.Id.TypeName = "Document"

newAttach.Id.Value = Guid.NewGuid.ToString

Dim newAttachName As New ClarizenSrv.FieldValue

newAttachName.FieldName = "Name"

newAttachName.Value = attach.FileName

newAttach.Values = New ClarizenSrv.FieldValue() {newAttachName}

Dim createAttach As New ClarizenSrv.CreateMessage

createAttach.Entity = newAttach

Dim newLink As New ClarizenSrv.GenericEntity

newLink.Id = New ClarizenSrv.EntityId

newLink.Id.TypeName = "AttachmentLink"

Dim newAttachParent As New ClarizenSrv.FieldValue

newAttachParent.FieldName = "Entity"

newAttachParent.Value = queryResult.Entities.ElementAt(ddIndex - 1).Id

Dim newAttachID As New ClarizenSrv.FieldValue

newAttachID.FieldName = "Document"

newAttachID.Value = newAttach.Id

newLink.Values = New ClarizenSrv.FieldValue() {newAttachParent, newAttachID}

Dim createLink As New ClarizenSrv.CreateMessage

createLink.Entity = newLink

Try

Dim upload As New ClarizenSrv.UploadMessage

upload.DocumentId = newAttach.Id

upload.FileInformation = New ClarizenSrv.FileInformation

upload.FileInformation.Storage = ClarizenSrv.Storage.Server

upload.FileInformation.FileName = attach.FileName

MsgBox("Uploading: " & attach.FileName, MsgBoxStyle.SystemModal)

upload.FileInformation.Content = System.IO.File.ReadAllBytes(path & "\" & attach.FileName)

Dim attachresults() As ClarizenSrv.Result = cClient.Execute(cSessionHeader, New ClarizenSrv.CallOptions, New ClarizenSrv.BaseMessage() {createAttach, createLink, upload})

' MsgBox(attachresults.Count, MsgBoxStyle.SystemModal)

Catch ex As Exception

End Try

Try

System.IO.File.Delete(path & "\" & attach.FileName)

Catch ex As Exception

End Try

End If

Next attach

End If

Logout(cClient)

Import from old forum 0 votes
Comment actions Permalink
0
Avatar

Hard to format in this editor and it won't let me upload a png or gif.

Import from old forum 0 votes
Comment actions Permalink
0
Avatar

You won't be able to change the SentBy and SentOn fields as they are populated automatically, but we will fix the SentBy field to show the current user instead of System.

 

Clarizen Team 0 votes
Comment actions Permalink
0
Avatar

[quote=Eyal Post]

You won't be able to change the SentBy and SentOn fields as they are populated automatically, but we will fix the SentBy field to show the current user instead of System.

 

[/quote]

 

<br><br>

Bummer.  Thanks for looking into this promptly.  Could you explain the difference between the tables Email and ReceivedMail? Is the email image that pops up when clicking the email icon stored in ReceivedMail?

Import from old forum 0 votes
Comment actions Permalink
0
Avatar

ReceivedMail is used for emails used by our Interact feature - It's not the entity type you need for your use case.

Clarizen Team 0 votes
Comment actions Permalink
0
Avatar

I was thinking that if I mocked the TrackIt process with a MessageID then I could get the results I wanted.

Import from old forum 0 votes
Comment actions Permalink
0
Avatar

Even if you could, the time fields would still be populated for you and it wouldn't have solved your problem.

 

Clarizen Team 0 votes
Comment actions Permalink
0
Avatar

Dang.  Thanks anyway.

 

Just to be sure I understand.  In the table Email there are only three fields I may set and reset: Comment, Subject and Visibility - because they are marked as Updateable?  And the field AttachedTo may be set upon creation but then may not be editable because it is marked as CreateOnly?

 

Thanks for your patience.

Import from old forum 0 votes
Comment actions Permalink
0
Avatar

I have decided to upload emails as a .msg file under documents instead of as a Clarizen email.  This way I can keep inline images and keep attachments associated with the email.  Attached is the new class that does all of the work.  This class:

  1. gets a list of a users work items
  2. uploads multiple emails at once to a work item
  3. upload a single file of any type or a folder shortcut to a work item
  4. downloads all emails, posts, notes and documents from a work item to a folder on the users PC.  Then will recurse each sub work item.
Mark Alford 0 votes
Comment actions Permalink
0
Avatar

If anybody is interested, I have made quite a few changes.  I'd be happy to share any code.  Next is creating work items for the ribbon.  See attached.

 

Mark Alford 0 votes
Comment actions Permalink
0
Avatar

Looks great, Mark! I'll definitely share it with my peers in Clarizen, and we may contact you for further information if that's OK with you.

Ophir Kenig 0 votes
Comment actions Permalink