Send pic emails?

bunji

Registered User.
Local time
Today, 13:45
Joined
Apr 26, 2005
Messages
124
Hi, I have written this code to send an email to a selected list, it works using the redemption code which will stop the Outlook access violation error. This is found at http://www.dimastr.com/redemption/ for those of you who what to try it. The coding takes the list creates an email puts the contents of a text file as the body of the email and then adds an attachments and off it goes. Fine it works a treat, but what if i want the body of the email to contain pics or some html code how can i add that to the body? Can anyone help.

My code so far is:

Code:
Public Function TestEmailInvite()

Dim db As DAO.Database
Dim MailList As DAO.Recordset

Dim OlApp As Outlook.Application
Dim olNamespace As Outlook.NameSpace
Dim OlFolder As Outlook.MAPIFolder
Dim OlMailItem As Outlook.MailItem
Dim objSafeMail As Redemption.SafeMailItem


Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Dim RecipName As String


    Set fso = New FileSystemObject
    Set db = CurrentDb()
    
    'Get the data
    Set MailList = db.OpenRecordset("QryCurrentUser")
    Do Until MailList.EOF

    RecipName = MailList("Name")
    
        Set OlApp = CreateObject("Outlook.application") 'Create an instance of Redemption.SafeMailItem
        Set olNamespace = OlApp.GetNamespace("MAPI")
        Set OlFolder = olNamespace.GetDefaultFolder(olFolderInbox)
        Set OlMailItem = OlFolder.Items.Add("IPM.note")

        BodyFile$ = "c:\harrodianNewsLetter\AirHarrodsInvite.doc"
      
    ' Check to make sure the file exists...
    If fso.FileExists(BodyFile$) = False Then

    MsgBox "The body file isn't where you say it is. " & vbNewLine & vbNewLine & _
           "Quitting...", vbCritical, "I Ain't Got No-Body!"
    Exit Function

    End If

        ' Since we got a file, we can open it up.
        Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False, TristateUseDefault)

        ' and read it into a variable.
        MyBodyText = MyBody.ReadAll

        ' and close the file.
        MyBody.Close

    'Give the email item its contents
    With OlMailItem
        .To = MailList("EmailAddress")
        .Subject = "Invite"
        .Body = "Dear " & RecipName & MyBodyText
        .Attachments.Add "c:\E-Shot\Invitation.pdf"

    End With
    
    Set objSafeMail = New Redemption.SafeMailItem
    objSafeMail.Item = OlMailItem
    objSafeMail.Send
    
            'instead of automaticially sending it
            'Uncomment the next line to see the email
            'And comment the " objSafeMail.Send" line above this.
            'objSafeMail.Display

    'And on to the next one...
    MailList.MoveNext

Loop

    'Cleanup after ourselves
    Set objSafeMail = Nothing
    Set OlMailItem = Nothing
    Set OlFolder = Nothing
    Set olNamespace = Nothing
    Set OlApp = Nothing

    MailList.Close
    Set MailList = Nothing
    db.Close
    Set db = Nothing
    
    MsgBox "All Emails have now been sent. "

End Function
 
Hi,
you will need to use a method which can create HTML or RTF e-mails.
Look at this sample (attached) I had put togethere a while back.
HTH
Good luck
 

Attachments

am i able to read in the body from a html file?
 
Well the example you gave me enables the user to type the email in the form.
However if you have 100 emails to send, you wont want to write each email, therefore like i originally did, the email address is got from the list of recipients you want it to go to (maillist) and then the body of the email is read from one text file located on the users hard disk.

So if i want to automattically create the body of the email as before but in html format, how can i read in a html file?
 
Hi,
the sample just shows to you how to create a simple HTML e-mail so that you can format it or do whatever you want to which other methods (e.g. SendObject) don't, as they only allow plain text.
So you will have to use the code in the sample and your scenario to populate the body and the to,cc,bcc,subject...areas the way you want to.
So you already had that working earlier with redepmtions, so just combine the two (ways you populated everything) and the method of sending (html sample).
HTH
Good luck
 
Excellent i got it to work, as i saved the html code as the text file and read the file in the same way, and just changing the format of the email itself as in your example made it work.

Many Thanks for your help
 
You're welcome.
Glad I could assist.
Good luck on future projects!
 

Users who are viewing this thread

Back
Top Bottom