Email body from file

Armitage2k

Registered User.
Local time
Today, 21:49
Joined
Oct 10, 2009
Messages
34
Hi!

Here my code for generating an email out of my database:
Code:
Private Sub SendEmail2_Click()
Dim EmailApp, NameSpace, EmailSend As Object
Dim strTitle, strFn, strLN, strBody As String


Set EmailApp = CreateObject("Outlook.Application")
If EmailApp Is Nothing Then Set EmailApp = CreateObject("Outlook.Application")
Set NameSpace = EmailApp.GetNamespace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)


strTitle = Me![Title]
strFn = Me![First Name]
strLN = Me![Last Name]
strBody = "Dear " & strTitle & " " & strFn & " " & strLN & "," & Chr(13) & Chr(13)
strBody = strBody & "Warm greetings!" & Chr(13) & Chr(13)
strBody = strBody & "My name is Lala." & Chr(13)
strBody = strBody & "I live in Lulu."
strBody = strBody & "Shipping method: " & [Position] & Chr(13)
strBody = strBody & "Date shipped: " & [Birthdate] & Chr(13)
strBody = strBody & "Tracking / Confirmation number: " & [ProfileID] & Chr(13)
strBody = strBody & "Sincerely," & Chr(13) & Chr(13)
strBody = strBody & "Acme Corporation"


If IsNull([Email]) Or ([Email]) = "" Then
       MsgBox "There is no E-mail address entered for this person!"
       Exit Sub
       
    Else
    
    With EmailSend
        .Subject = "Warm Greetings!"
        .To = Me.Email
        '.CC = ""
        '.From = "some@one.com"
        .Body = strBody
        '.Attachments.Add "C:\attachment.txt"
        '.Attach = strFilePath & "\" & strFileName
        '.AttachFile strFilePath & "\" & strFileName, strFileName
        .Display
    End With
    
End If

Set EmailApp = Nothing
Set NameSpace = Nothing
Set EmailSend = Nothing

End Sub

What I would like to do is to get the message body from a textfile instead of entering it as a string directly into the code.
However, this method should be reliable in terms of format, e.g. I need to have linebreaks in the email exactly like in textfile, etc.

I would appreciate every help!
A2k
 
Last edited:
so? you think i did not use google before? I am posting here exactly because I cannot find what I need via google....

I would appreciate if someone could help me with my problem.
thanks,
A2k
 
I don't think its do-able (You will need to check with someone a bit knowledgeable than myself) - however can you not dump into word and email out ?


The problem you have is the body of the email will just be text and a jumble (return carrages and any formatting shot to bits)

if its do-able then you need to do it html - I have seen a sample that allows Access to be written in this format - then its just a handshake between Access and outlook - (again beyond my knowledge)

i would search in the sample section for html formatting /emailing

I know its not the answer you are looking for - but it might be a bit more helpful than you have already been given
 
A way to do it is

1. Access opens a Word doc and inserts the required data into Bookmarks

2. The Word doc is then use for the email body. If SMTP is used instead of Outlook then the code needs to save the Word doc as an HTML file and that is used for the email
 
Mikes you man on this - your handshake then is Access to word to outlook
 
I don't know if this helps at all, but I had to do a similar thing to this in an application I'm working on at the moment.

I stored my email body templates in a memo field in a table, with line breaks etc, and just put placeholders where I wanted the data inserted, so the template text might look like this:
Dear [CARDHOLDERNAME]

Attached to this email message, please find your transaction log numbered: [TLOGNUM], for month: [LOGMONTH].

If you have any queries regarding this log, please in the first instance contact your controller: [CONTROLLERNAME].

Then in my code, I read the memo contents into a string variable called strMailBody

Then I do a series of replace operations, inserting variable values in place of the placeholders i.e.

strMailBody = Replace(strMailbody,"[CARDHOLDERNAME]",strCardholder)
strMailBody = Replace(strMailbody,"[TLOGNUM]",intLogNumber)
strMailBody = Replace(strMailbody,"[LOGMONTH]",format(LogDate,"MM/YYYY"))
strMailBody = Replace(strMailbody,"[CONTROLLERNAME]",strControllerName)

-and I then have a formatted email body text containing inserted variables. I think it probably even works with rtf formatted text, but I haven't tested this.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom