Results 1 to 10 of 10
  1. #1
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398

    Generating and sending emails through Access

    I've recently determined that emails I'm creating in Access 2010, and mailing through Outlook 2010 have this extra information added to the email message.

    Date: Thu, 6 Jun 2013 15:39:48 -0600
    Message-ID: <001801ce62fe$5e667030$1b335090$@safecarautotranspo rt.com>
    MIME-Version: 1.0
    Content-Type: text/plain;
    charset="us-ascii"
    Content-Transfer-Encoding: 7bit
    X-Mailer: Microsoft Outlook 14.0
    Thread-Index: Ac5i/l4qKwb5cN9kTkqZ8bktPFz+qA==
    Content-Language: en-us

    Here's my code for creating and sending the email. You'll see that I remarked out the HTMLBody and the Attachement. So in essence I'm sending a blank email with only the subject. If I send a blank email from the same email account within Outlook, the recipient receives a blank email. It does not contain the above info. So somehow, this info is being created when the email is created in Outlook.
    Dim objAccount As Outlook.Account
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem

    'Determine the correct account
    For Each objAccount In Outlook.Application.Session.Accounts

    If objAccount = "Dispatcher" Then

    'Create the Outlook session.
    Set objOutlook = GetObject(, "Outlook.Application")
    'Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    With objOutlookMsg
    .To = strEmailAddress
    .SendUsingAccount = objAccount
    .Subject = "Safe Car Auto Transport Quote for your " & Me.VehicleMake & " " & Me.VehicleModel
    '.HTMLBody = ContractMessage(strCustomerName)
    '.Attachments.Add contractfile
    .send
    '.Display
    End With


    End If
    Next



    I've been working with my web hosting company for the last 2 hours, and we've deduced the problem exists within Access. Any suggestions?

  2. #2
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    I've determined that if I replace .Subject with a static text, it works properly. Example, .Subject = "Safe Car Auto Transport Quote" works perfectly. If I use any variable in the subject line, the code is inserted into the received email. Anyone see this before?

  3. #3
    DepricatedZero's Avatar
    DepricatedZero is offline Cthulhu Fhtagn!
    Windows 8 Access 2007
    Join Date
    Apr 2013
    Location
    Cincinnati
    Posts
    65
    Maybe I'm misunderstanding. This looks like a standard email header (as in, similar to an http header, not like page header).

    Is that text appearing in the actual body of the email? It shouldn't, but it should still be in the file itself, I believe. Mail servers aren't my forte though.

    If it's appearing in the body you may have something 'hanging open' so to speak so that it's inserting the header as text rather than a header.
    Last edited by DepricatedZero; 06-07-2013 at 07:20 AM. Reason: noob error, html != http

  4. #4
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    Yes, the "header" text appears in the very beginning of the email.

    The problem is with .Subject. If I assign .Subject a static line of text, the "header" text does not appear. If I assign .Subject a variable, the "header" text appears.

  5. #5
    DepricatedZero's Avatar
    DepricatedZero is offline Cthulhu Fhtagn!
    Windows 8 Access 2007
    Join Date
    Apr 2013
    Location
    Cincinnati
    Posts
    65
    Is .Subject = "Safe Car Auto Transport Quote for your " & Me.VehicleMake & " " & Me.VehicleModel

    producing the error? Or not? I mean - does having the variable in there cause it, or is it when it's only a variable that it happens?

  6. #6
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    Yes, that statement produces the error.

    I have not tried it with only a variable.

    I know that statement is correct because when I view the email in my sent folder, the email is correct, and the subject line is the correct statement.

  7. #7
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    I just assigned .Subject = Me.VehicleMake, and the error was produced.

  8. #8
    DepricatedZero's Avatar
    DepricatedZero is offline Cthulhu Fhtagn!
    Windows 8 Access 2007
    Join Date
    Apr 2013
    Location
    Cincinnati
    Posts
    65
    One thing you might try is using a blank template?

    Something like

    Set objOutlookMsg = objOutlook.CreateItemFromTemplate(GetPath)

    My own mailer module uses this to load prebuilt templates and then patterned string replacement to populate relevant data.

    This is a workaround rather than a fix, really - but I honestly couldn't say why populating the subject from a variable would cause it to dump the header into the body. You might debug.print the variable before putting it into the subject and see if it's sending something funky though?

    Edit: On that note, try ending capping it with a zero length string ie

    .Subject = me.VehicleMake & ""

    And if that doesn't work add a space and see if that fixes it.

  9. #9
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    Thanks for the suggestions. I'll try them.

    It took me a while to get a handle on this. It was really confusing with the item in the sent folder "appearing" correct.

  10. #10
    DepricatedZero's Avatar
    DepricatedZero is offline Cthulhu Fhtagn!
    Windows 8 Access 2007
    Join Date
    Apr 2013
    Location
    Cincinnati
    Posts
    65
    Made any progress on this?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Sending Emails and VBA coding
    By lucy1216 in forum Programming
    Replies: 4
    Last Post: 05-20-2013, 05:57 AM
  2. Replies: 1
    Last Post: 11-14-2012, 01:43 PM
  3. Sending emails from Acess Database
    By Lirizarry in forum Access
    Replies: 3
    Last Post: 01-26-2012, 10:04 PM
  4. Generating emails with email-address in body
    By techexpressinc in forum Programming
    Replies: 1
    Last Post: 08-17-2011, 01:48 PM
  5. Sending multiple emails
    By Petefured in forum Programming
    Replies: 0
    Last Post: 05-24-2011, 03:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums