Re: Attachments problems with Redemption

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Aug 6, 4:18 pm, "Ken Slovak - [MVP - Outlook]" <kenslo...@xxxxxxxx>
wrote:
If what you're adding are actual JPG files I don't understand why you need
the lines that set the MAPI properties to begin with. Why not just add the
files as attachments either to the Safe item or the underlying Outlook item?

If what you're adding is binary bytes stored as a blob in a database table
then you'd have to write the content as a binary array to the
PR_ATTACH_DATA_BIN (0x37010102) property as well as setting various other
attachment properties but it's much easier to just add a file, even if it is
an image file.

If you must set PR_ATTACH_DATA_BIN with a binary blob then there are other
properties that must be set also, use a MAPI viewer such as OutlookSpy or
MFCMAPI to take a look at all the properties that are set on an attached
image file.

Personally I'd just save the binary blob to the file system in a temp folder
as a file and then attach that file to the item and then delete the temp
file.

--
Ken Slovak
[MVP - Outlook]http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm

<k9byt...@xxxxxxxxx> wrote in message

news:1186428832.149075.223230@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Aug 6, 1:51 pm, "Dmitry Streblechenko" <dmi...@xxxxxxxxxxx> wrote:
<snip>

Thanks for your help,

I followed your suggestion, and changed my code to

Set Attach = mySafeItem.Attachments.Add(PetPic)
With Attach
.Fields(&H370E001E) = "image/jpeg"
.Fields(&H3712001E) = "PetPic"
End With

and still gives me the same error. If I comment out the folllowing:

With Attach
.Fields(&H370E001E) = "image/jpeg"
.Fields(&H3712001E) = "PetPic"
End With

everything works out fine. I'm not using relative paths. I just have
an ado bound to a table, and when I try to access it the error Could
Not Find File Program Files\Common FIles\SYSTEM\MSMAPI

\1033\db.mdb pops up

Thanks once again. Hope that someone out there can share a suggestion
that could solve the problem

Could you refer me to a simple example that just uses a JPG attachment
as you suggest? I'm attaching my complete code just in case I'm
missing something here. I don't mind rewriting the whole thing, so, if
you have an example somewhere that I could use I would be more than
happy to switch my code around. The only reason why I was using
the .Fields(&H370E001E) = "image/jpeg" is because I found some sample
code Googling around, and I modified it for my app.... Thanks once
again for your time and effort


Public Sub cmdEmailwithData(HTMLfile As String, EmailSubject As
String, CustomerID As Long, petName As String, ReferenceNumber As
String, datIn As Date, datOut As Date, petID As Long)
Dim count As Integer
Dim msgBase As String
Dim msg As String
Dim LastID As Long
Dim intFileHandle As Integer
Dim str As String
Dim KennelLogo As String
Dim PetPic As String
On Error GoTo handler
'get customer info using its id
If Not isFormLoaded("frmCustomer") Then
If DataEnv.rsCustomer.State = 1 Then DataEnv.rsCustomer.Close
DataEnv.customer (CustomerID)
If DataEnv.rsCustomer.RecordCount = 0 Then
Exit Sub
End If
If DataEnv.rsPetFromID.State = 1 Then
DataEnv.rsPetFromID.Close
DataEnv.PetFromID (petID)
If DataEnv.rsPetFromID.RecordCount = 0 Then
Exit Sub
End If
DataEnv.rsPetFromID.MoveFirst
End If
If DataEnv.rsCustomer!Email <> "" Then
If DataEnv.rsKennelInfo.State = 0 Then
DataEnv.rsKennelInfo.Open

'outlook is runnign
Dim outlookRunning As Boolean
Set myOlApp = GetObject("", "Outlook.Application")
If Err.Number = 0 And myOlApp.Explorers.count > 0 Then
outlookRunning = True
Else
outlookRunning = False
End If
Set myOlApp = Nothing
'prepare to send emails using redemption
Set myOutlook = CreateObject("Outlook.Application")
Set myNameSpace = myOutlook.GetNamespace("MAPI")
myNameSpace.Logon
Dim myItem As Object
Dim mySafeItem As Redemption.SafeMailItem
Set mySafeItem = New Redemption.SafeMailItem
Set myItem = myOutlook.CreateItem(0) 'Create a new message

'Get email template from HTML file
msgBase = getHTMLfile(HTMLfile)

'kennel logo
If DataEnv.rsKennelInfo!LogoName <> "" Then
If glbKennel.getVersion <> 2 Then
KennelLogo = App.path & "\Pictures\" &
DataEnv.rsKennelInfo!LogoName
Else
KennelLogo = DataEnv.rsKennelInfo!LogoName
End If
msgBase = FindReplaceEmail(msgBase, "<IMG
SRC=KennelLogo>", "<IMG SRC=""" & KennelLogo & """>")
Else
KennelLogo = ""
msgBase = FindReplaceEmail(msgBase, "<IMG
SRC=KennelLogo>", "")
End If
'pet pic
If DataEnv.rsPet!pic <> "" Then
If (glbKennel.getLocalComputerName = glbKennel.getServer
And glbKennel.getVersion = 2) Or glbKennel.getVersion <> 2 Then
PetPic = App.path & "\Pictures\Pets\" & DataEnv.rsPet!
pic
Else
PetPic = "k:\K9 Koordinator\Pictures\Pets\" &
DataEnv.rsPet!pic
End If
msgBase = FindReplaceEmail(msgBase, "<IMG SRC=PetPic>",
"<IMG SRC=""" & PetPic & """>")
Else
PetPic = ""
msgBase = FindReplaceEmail(msgBase, "<IMG SRC=PetPic>",
"")
End If

'Replace in general info, i.e. Name,Address,Phone(s),Fax
msgBase = FindReplaceEmail(msgBase, "KennelName",
glbKennel.KennelName)
msgBase = FindReplaceEmail(msgBase, "KennelAddress",
glbKennel.KennelAddress)
msgBase = FindReplaceEmail(msgBase, "KennelPhone1",
glbKennel.KennelPhone1)
msgBase = FindReplaceEmail(msgBase, "KennelPhone2",
glbKennel.KennelPhone2)
msgBase = FindReplaceEmail(msgBase, "KennelFax",
glbKennel.KennelFax)
msgBase = FindReplaceEmail(msgBase, "KennelEmail",
DataEnv.rsKennelInfo!KennelEmail)
msgBase = FindReplaceEmail(msgBase, "KennelWebsite",
DataEnv.rsKennelInfo!KennelWebsite)

'Email Subject
EmailSubject = EmailSubject & " from " & glbKennel.KennelName

'Replace Keywords
msg = msgBase
msg = FindReplaceEmail(msg, "CustomerTitle",
DataEnv.rsCustomer!Title)
msg = FindReplaceEmail(msg, "CustomerName", DataEnv.rsCustomer!
FName & " " & DataEnv.rsCustomer!lname)
msg = FindReplaceEmail(msg, "PetName", petName)
msg = FindReplaceEmail(msg, "ScheduledDateIn", datIn)
'If datIn = datOut Then
' msg = FindReplaceEmail(msg, "ScheduledDateOut", "")
'Else
msg = FindReplaceEmail(msg, "ScheduledDateOut", datOut)
'End If
msg = FindReplaceEmail(msg, "ReferenceNumber",
ReferenceNumber)

'Send email
Call sendEmail(DataEnv.rsCustomer!Email, EmailSubject, msg,
KennelLogo, PetPic, myItem, mySafeItem, datIn, True)

'click send receive - if outlook open, otherwise error
If outlookRunning Then
Set btn =
myOutlook.ActiveExplorer.CommandBars.FindControl(1, 7095)
btn.Execute
End If
'dereference all
Set myOutlook = Nothing
Set myNameSpace = Nothing
Set mySafeItem = Nothing
Set myItem = Nothing
Set Attach = Nothing
Set btn = Nothing
End If
Exit Sub
handler:
Call BasicError("Error occurred sending email")
End Sub

Public Sub sendEmail(MsgTo As String, MsgSubject As String, msg As
String, KennelLogo As String, PetPic As String, myItem As Object,
mySafeItem As Object, dat As Date, res As Boolean)
On Error GoTo handler
'using Redemption - No Security Warning
myItem.HTMLBody = msg
myItem.To = MsgTo
myItem.Subject = MsgSubject
mySafeItem.Item = myItem

With mySafeItem.Attachments
.Add (KennelLogo)
.Add (PetPic)
End With

mySafeItem.Send
Set myItem = Nothing
Set mySafeItem = Nothing
Exit Sub
handler:
Call BasicError("Error occurred sending email" & Chr(13) &
Err.Description)
End Sub

.



Relevant Pages

  • Re: Attachments problems with Redemption
    ... Dim o ... Public Sub sendEmail(MsgTo As String, MsgSubject As String, msg As ... Dim msgBase As String ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: MIME::Lite Trouble - please guide me
    ... $msg = new MIME::Lite ... # As a string... ... Just to explain that you of cause also can attach more than one file ...
    (comp.lang.perl.modules)
  • Re: English Ivy, training to grow on Smooth Vinyl Fence
    ... One, attaching string to the ground might be easy enough, but I can't ... damaging the fence or nearby bushes and trees...I don't want to attach ... fence--it would be one more thing to contend with, the ivy will end up ...
    (rec.gardens)
  • Re: GRAND SLAM SIDE WINDER CHRISTMAS CONTEST
    ... Attach a VERY long string to one end of the bobbin, ... through the doorways, under the bed, etc ... ...
    (rec.crafts.textiles.quilting)
  • Starting rsync via ASP.Net
    ... web front end to allow our non-technical staff to make changes to sites ... // Attach the output for reading ... // Read the sOut to a string. ...
    (microsoft.public.dotnet.framework.aspnet)