H
Henrik Andre Tellevik
Could anyone please tell me why this code will not work? I have used the
example (http://www.outlookcode.com/d/code/htmlimg.htm) to attach the graphic
but it keeps showing up as an attachment and a red x in the box where the
graphic goes.
my code:
Public Sub overFørAttachments(ByRef tilMail As Outlook.MailItemClass)
On Error Resume Next
Dim oSession As MAPI.Session
' CDO objects
Dim oMsg As MAPI.Message
Dim oAttachs As MAPI.Attachments
Dim oAttach As MAPI.Attachment
Dim colFields As MAPI.Fields
Dim oField As MAPI.Field
Dim colAttach As Outlook.Attachments
Dim l_Attach As Outlook.Attachment
' CDO objects
Dim strEntryID As String
Dim teller As Integer
Dim strCID As String
Dim navnPaaImage As String
Dim folder As String
folder = "C:\Programfiler\bit\Outlook_Add-in\Sent Attachments\"
teller = 1
'add graphic as attachment to Outlook message
' change path to graphic as needed
colAttach = tilMail.Attachments
Dim attach As Outlook.Attachment
For Each attach In m_objMail.Attachments
tilMail.Save()
If Not attach.FileName.IndexOfAny(IkkeInneholde) = -1 Then
Dim saveFileAs As String
saveFileAs = attach.FileName
Do While saveFileAs.IndexOfAny(IkkeInneholde) <> -1
saveFileAs =
saveFileAs.Remove(saveFileAs.IndexOfAny(IkkeInneholde), 1)
Loop
attach.SaveAsFile(folder & saveFileAs)
'nyAttach = sendeMail.Attachments.Add(folder & saveFileAs,
Outlook.OlAttachmentType.olByValue, attach.Position, attach.FileName)
l_Attach = colAttach.Add(folder & saveFileAs, , ,
attach.FileName)
Else
attach.SaveAsFile(folder & attach.FileName)
'nyAttach = sendeMail.Attachments.Add(folder &
attach.FileName, Outlook.OlAttachmentType.olByValue, attach.Position,
attach.FileName)
l_Attach = colAttach.Add(folder & attach.FileName, , ,
attach.FileName)
End If
tilMail.Save()
Next
' *** POSITION CRITICAL *** you must dereference the
' attachment objects before changing their properties
' via CDO
tilMail.Save()
tilMail.Close(Outlook.OlInspectorClose.olDiscard)
strEntryID = tilMail.EntryID
Marshal.ReleaseComObject(tilMail)
Marshal.ReleaseComObject(colAttach)
Marshal.ReleaseComObject(l_Attach)
oSession = CreateObject("MAPI.Session")
oSession.Logon("", "", False, False)
' get the message created earlier
oMsg = oSession.GetMessage(strEntryID)
' set properties of the attached graphic that make
' it embedded and give it an ID for use in an <IMG> tag
oAttachs = oMsg.Attachments
If teller <= oAttachs.Count Then
Do While teller <= oAttachs.Count
oAttach = oAttachs.Item(teller)
'&H370E001E
MsgBox(oAttach.Fields(&H3712001E).value)
strCID = oAttach.Fields(&H3712001E).value
If strCID = "" Then
strCID = "not embedded"
Else
'navnPaaImage = "attachment" & teller
colFields = oAttach.Fields
oField =
colFields.Add(MAPI.CdoPropTags.CdoPR_ATTACH_MIME_TAG, "image/jpeg")
oField = colFields.Add(&H3712001E, "myident")
oMsg.Fields.Add("{0820060000000000C000000000000046}0x8514", 11, True)
oMsg.Update()
End If
teller = teller + 1
Loop
oMsg.Update()
' get the Outlook MailItem again
tilMail =
m_objOutlook.GetNamespace("MAPI").GetItemFromID(strEntryID)
' add HTML content -- the <IMG> tag
Dim start As String
start = 1
Do While start <= oAttachs.Count
tilMail.HTMLBody = tilMail.HTMLBody & vbNewLine & "<IMG
align=baseline border=0 hspace=0 src=cid:myident>"
start = start + 1
Loop
'm_objMail.Close(Outlook.OlInspectorClose.olSave)
tilMail.Close(Outlook.OlInspectorClose.olSave)
tilMail.Display()
Else
tilMail =
m_objOutlook.GetNamespace("MAPI").GetItemFromID(strEntryID)
End If
' clean up objects
oMsg = Nothing
oAttachs = Nothing
oAttach = Nothing
oField = Nothing
colFields = Nothing
oSession.Logoff()
oSession = Nothing
End Sub
example (http://www.outlookcode.com/d/code/htmlimg.htm) to attach the graphic
but it keeps showing up as an attachment and a red x in the box where the
graphic goes.
my code:
Public Sub overFørAttachments(ByRef tilMail As Outlook.MailItemClass)
On Error Resume Next
Dim oSession As MAPI.Session
' CDO objects
Dim oMsg As MAPI.Message
Dim oAttachs As MAPI.Attachments
Dim oAttach As MAPI.Attachment
Dim colFields As MAPI.Fields
Dim oField As MAPI.Field
Dim colAttach As Outlook.Attachments
Dim l_Attach As Outlook.Attachment
' CDO objects
Dim strEntryID As String
Dim teller As Integer
Dim strCID As String
Dim navnPaaImage As String
Dim folder As String
folder = "C:\Programfiler\bit\Outlook_Add-in\Sent Attachments\"
teller = 1
'add graphic as attachment to Outlook message
' change path to graphic as needed
colAttach = tilMail.Attachments
Dim attach As Outlook.Attachment
For Each attach In m_objMail.Attachments
tilMail.Save()
If Not attach.FileName.IndexOfAny(IkkeInneholde) = -1 Then
Dim saveFileAs As String
saveFileAs = attach.FileName
Do While saveFileAs.IndexOfAny(IkkeInneholde) <> -1
saveFileAs =
saveFileAs.Remove(saveFileAs.IndexOfAny(IkkeInneholde), 1)
Loop
attach.SaveAsFile(folder & saveFileAs)
'nyAttach = sendeMail.Attachments.Add(folder & saveFileAs,
Outlook.OlAttachmentType.olByValue, attach.Position, attach.FileName)
l_Attach = colAttach.Add(folder & saveFileAs, , ,
attach.FileName)
Else
attach.SaveAsFile(folder & attach.FileName)
'nyAttach = sendeMail.Attachments.Add(folder &
attach.FileName, Outlook.OlAttachmentType.olByValue, attach.Position,
attach.FileName)
l_Attach = colAttach.Add(folder & attach.FileName, , ,
attach.FileName)
End If
tilMail.Save()
Next
' *** POSITION CRITICAL *** you must dereference the
' attachment objects before changing their properties
' via CDO
tilMail.Save()
tilMail.Close(Outlook.OlInspectorClose.olDiscard)
strEntryID = tilMail.EntryID
Marshal.ReleaseComObject(tilMail)
Marshal.ReleaseComObject(colAttach)
Marshal.ReleaseComObject(l_Attach)
oSession = CreateObject("MAPI.Session")
oSession.Logon("", "", False, False)
' get the message created earlier
oMsg = oSession.GetMessage(strEntryID)
' set properties of the attached graphic that make
' it embedded and give it an ID for use in an <IMG> tag
oAttachs = oMsg.Attachments
If teller <= oAttachs.Count Then
Do While teller <= oAttachs.Count
oAttach = oAttachs.Item(teller)
'&H370E001E
MsgBox(oAttach.Fields(&H3712001E).value)
strCID = oAttach.Fields(&H3712001E).value
If strCID = "" Then
strCID = "not embedded"
Else
'navnPaaImage = "attachment" & teller
colFields = oAttach.Fields
oField =
colFields.Add(MAPI.CdoPropTags.CdoPR_ATTACH_MIME_TAG, "image/jpeg")
oField = colFields.Add(&H3712001E, "myident")
oMsg.Fields.Add("{0820060000000000C000000000000046}0x8514", 11, True)
oMsg.Update()
End If
teller = teller + 1
Loop
oMsg.Update()
' get the Outlook MailItem again
tilMail =
m_objOutlook.GetNamespace("MAPI").GetItemFromID(strEntryID)
' add HTML content -- the <IMG> tag
Dim start As String
start = 1
Do While start <= oAttachs.Count
tilMail.HTMLBody = tilMail.HTMLBody & vbNewLine & "<IMG
align=baseline border=0 hspace=0 src=cid:myident>"
start = start + 1
Loop
'm_objMail.Close(Outlook.OlInspectorClose.olSave)
tilMail.Close(Outlook.OlInspectorClose.olSave)
tilMail.Display()
Else
tilMail =
m_objOutlook.GetNamespace("MAPI").GetItemFromID(strEntryID)
End If
' clean up objects
oMsg = Nothing
oAttachs = Nothing
oAttach = Nothing
oField = Nothing
colFields = Nothing
oSession.Logoff()
oSession = Nothing
End Sub