| | Awarded by Microsoft since 2005: |  |
| | VBOffice Info | | Visitors | 1388653 | | Impressions | 5086109 |
| |
|
| |
| Author: Michael Bauer | Homepage | | Date: 20.05.2006 | Accessed: 24932 | | | | Description
We are very sorry! This description is not translated yet. Anyway, please try the code as it is self-explanatory. |
Private Type EmbeddedObj
Key As String
Type As String
Source As String
Tag As String
Description As String
End Type
Private m_SafeMail As Object
Private m_Buffer As String
Private m_StartPos As Long
Private m_EndPos As Long
Public Sub AufrufBeispiel()
Dim ImageMail As MailItem
Dim AudioMail As MailItem
Dim imgf$, audf$
imgf = "d:\laugh.gif"
audf = "d:\qopen.wav"
Set ImageMail = Application.CreateItem(olMailItem)
ImageMail.BodyFormat = olFormatHTML
Set AudioMail = ImageMail.Copy
ImageMail.Subject = "test image"
ImageMail.HTMLBody = "Image des Tages: @0 - und weiter im Text"
ImageMail.Display
AddEmbeddedAttachment ImageMail, imgf, "@0", "(Image des Tages)"
AudioMail.Subject = "test audio"
AudioMail.Display
AddEmbeddedAttachment AudioMail, audf
End Sub
Public Sub AddEmbeddedAttachment(Mail As Outlook.MailItem, _
File As String, _
Optional PositionID As String, _
Optional Description As String _
)
On Error GoTo AUSGANG
Dim Obj As EmbeddedObj
Mail.Save
Set m_SafeMail = CreateSafeItem(Mail)
m_Buffer = m_SafeMail.HTMLBody
Obj.Source = File
Obj.Description = Description
Obj.Type = GetContentType(GetExtension(File))
Obj.Key = GetNewID
FindPosition PositionID
Select Case left$(Obj.Type, 1)
Case "i"
CreateImageTag Obj
Case "a"
CreateAudioTag Obj
Case Else
GoTo AUSGANG
End Select
AddAttachment Obj
InsertTagIntoMail Obj.Tag
AUSGANG:
ReleaseSafeItem m_SafeMail
End Sub
Private Function GetContentType(Extension As String) As String
Select Case Extension
Case "wav", "wma"
GetContentType = "audio/" & Extension
Case "avi"
GetContentType = "video/" & Extension
Case "gif", "jpg", "jpeg", "bmp", "png"
GetContentType = "image/" & Extension
End Select
End Function
Private Function GetExtension(File As String) As String
GetExtension = Mid$(File, InStrRev(File, ".") + 1)
End Function
Private Function GetNewID() As String
Randomize
GetNewID = CStr(Int((99999 - 10000 + 1) * Rnd + 10000))
End Function
Private Sub FindPosition(Find As String)
Dim posAnf As Long
Dim posEnd As Long
If Len(Find) Then
posAnf = InStr(m_Buffer, Find)
If posAnf Then
posEnd = posAnf + Len(Find) - 1
End If
End If
If posAnf = 0 Then
posAnf = InStr(1, m_Buffer, "</body>", vbTextCompare)
If posAnf = 0 Then
posAnf = Len(m_Buffer) + 1
End If
posEnd = posAnf - 1
End If
m_StartPos = posAnf
m_EndPos = posEnd
End Sub
Private Sub CreateImageTag(Obj As EmbeddedObj)
Obj.Tag = "<img src='cid:" & Obj.Key
Obj.Tag = Obj.Tag & "' align=baseline border=0 hspace=0"
If Len(Obj.Description) Then
Obj.Tag = Obj.Tag & " alt='" & Obj.Description & "'>"
Else
Obj.Tag = Obj.Tag & ">"
End If
End Sub
Private Sub CreateAudioTag(Obj As EmbeddedObj)
Obj.Tag = "<bgsound src='cid:" & Obj.Key & "'>"
End Sub
Private Sub AddAttachment(Obj As EmbeddedObj)
Dim Attachment As Object
Dim PR_HIDE_ATTACH As Long
Const PT_BOOLEAN As Long = 11
PR_HIDE_ATTACH = _
m_SafeMail.GetIDsFromNames("{00062008-0000-0000-C000-000000000046}", _
&H8514) Or PT_BOOLEAN
m_SafeMail.Fields(PR_HIDE_ATTACH) = True
Set Attachment = m_SafeMail.Attachments.Add(Obj.Source)
Attachment.Fields(&H370E001E) = Obj.Type
Attachment.Fields(&H3712001E) = Obj.Key
Set Attachment = Nothing
End Sub
Private Sub InsertTagIntoMail(Tag As String)
m_Buffer = left$(m_Buffer, m_StartPos - 1) _
& Tag & _
right$(m_Buffer, Len(m_Buffer) - m_EndPos)
m_SafeMail.HTMLBody = m_Buffer
End Sub
|
| | |
| | |  | ReplyAll alerts you before unintentionally replying all, or if you are a confidential BCC recipient of the ... [more] |
| | |  | Access the master category list in the blink of an eye, share your categories in a network, get a reminder service, and ... [more] |
| | |  | SAM automatically sets the sender, signature, and folder for sent items, for instance based on the recipient ... [more] |
| | |  | OLKeeper reliably prevents users from closing their Outlook window and thus possibly missing reminders or ... [more] |
| |
|