Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195

    image to mail body

    hi guys, can anyone help how to embed an image to a mail body ?? the following code sends the mail and the mail just says embedded image:

    thank you



    Code:
    Dim SendID
    Dim Subject
    Dim Body
    Dim olMail As MailItem
    Set otlApp = CreateObject("Outlook.Application")
    Set olMail = otlApp.CreateItem(olMailItem)
    
    Dim oAttach As Outlook.Attachment
    SendID = "me@home.com"
    With olMail
    .To = SendID
    If CCID <> "" Then
    .CC = CCID
    End If
    .Subject = "picture embedded"
    .Attachments.Add "C:\Users\Dave Moses\Desktop\Links\Stairlift Pics\My picture.jpg", olByValue, 0
    .HTMLBody = .HTMLBody & "<br><B>Embedded Image:</B><br>" _
    & "<img src=?cid:My picture.jpg?" & "width=?500' height=?200?><br>" _
    & "<br>Best Regards, <br>Sumit</font></span>"
    .Display
    .Send
    End With
    MsgBox ("your Mail has been sent to " & SendID)
    

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Either use literal string for filepath or concatenate variable. Example:

    "<img src='C:\Users\Dave Moses\Desktop\Links\Stairlift Pics\My picture.jpg' width='500' height='200'>"

    If you want to embed picture in body, then why Attachments.Add?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi June7, thank you for your reply, I will try this in a while, your questions as to why is probably because I don't fully understand, this was copied code and adapted

  4. #4
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi June7, just tried adapting and still send mail with no pictire and the mail body says Embedded image:

    Where am i going wrong ???

    Code:
    Dim SendID
    Dim Subject
    Dim Body
    Dim olMail As MailItem
    Set otlApp = CreateObject("Outlook.Application")
    Set olMail = otlApp.CreateItem(olMailItem)
    
    Dim oAttach As Outlook.Attachment
    SendID = "me@home.com"
    With olMail
    .To = SendID
    .Subject = "Handicare"
    .HTMLBody = .HTMLBody & "<br><B>Embedded Image:</B><br>" _
    & "<img src='C:\Users\My Name\Desktop\Links\Stairlift Pics\My Picture.jpg' width='500' height='200'>" _
    & "<br>Best Regards, <br>Dave</font></span>"
    .Display
    .Send
    End With
    MsgBox ("your Mail has been sent to " & SendID)

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    I see </font></span> end tags but no opening tags. Tested that and email body still builds with image.

    I run .Display before .HTMLBody, although tested your sequence and still included image.

    Are you certain filepath for Desktop folder is correct? You had Dave Moses in the path in original post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Yes, took my name out but i guess it doesn't matter, would you kindly adjust the code and i can set the path etc.... i ma certain the path is correct because i get that from properties of the image the copy location

  7. #7
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    I am unsure where i am wrong! willl run it and snippet the email body i get

  8. #8
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi June7 this is what i have got

    Click image for larger version. 

Name:	Capture.JPG 
Views:	15 
Size:	28.2 KB 
ID:	39310

  9. #9
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi June7, i have this a little closer now by adding i cid, the picture now goes to mail body but cannot dispaly, would you correct the code whereever i am wrong ???

    Result of code below

    Click image for larger version. 

Name:	Capture.JPG 
Views:	15 
Size:	19.0 KB 
ID:	39311

    Code:
    Dim SendID
    Dim Subject
    Dim Body
    Dim olMail As MailItem
    Set otlApp = CreateObject("Outlook.Application")
    Set olMail = otlApp.CreateItem(olMailItem)
    
    Dim oAttach As Outlook.Attachment
    SendID = "dave@dmoses.co.uk"
    With olMail
    .To = SendID
    .Subject = "Handicare"
    .HTMLBody = .HTMLBody & "<br><B>Embedded Image:</B><br>" _
    & "<img src='cid:C:\Users\Dave Moses\Desktop\Links\Stairlift Pics\Minivator 950 Plus.jpg' width='500' height='200'>" _
    & "<br>Best Regards, <br>Dave</font></span>"
    .Display
    End With

  10. #10
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Post 9 to confirm location

    Attachment 39312

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Don't know how the code should be corrected because the original structure works for me. I do not use 'cid:'. In fact, adding it causes my image to fail to load in email and produces the error you posted.

    Whatever you tried to attach I can't open, get 'invalid' error.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi June7, took out cid, still doesn't embed the image, will that be an outlook setting ?

    Kindest

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    I am not aware of any Outlook, Access, or Windows setting that would affect this.

    Sorry, since code works for me I cannot explain why it fails for you.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Although we don't know each other, would you remote in via team viewer and check or do you think that it wouldn't achieve the result ?

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    I don't think it would make a difference. It would still be same code running on same system. I tested with image in folder on desktop. You might test with image in a regular folder.

    Just thought of an Outlook setting that might affect this. If email is set for plain text, HTML code will be ignored. In Outlook > File > Options > Mail > Compose Messages > select format. Mine is set for HTML as default.

    Well, just did some tests with alternate settings. Does not make a difference. Email created by code still opens as HTML format.

    Sorry, am at a loss.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. add bmp from word doc to mail body
    By DMT Dave in forum Access
    Replies: 1
    Last Post: 05-22-2018, 05:53 PM
  2. Adding report content into e-mail Body
    By Toasty in forum Access
    Replies: 22
    Last Post: 08-01-2014, 11:56 AM
  3. Replies: 5
    Last Post: 07-02-2014, 12:15 AM
  4. send email with attached image in body
    By trevor40 in forum Programming
    Replies: 5
    Last Post: 02-14-2014, 01:17 AM
  5. Replies: 5
    Last Post: 10-29-2012, 05:53 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