Picture sent in body (not attached) by automated E-Mail (1 Viewer)

  • Thread starter Deleted member 162737
  • Start date
D

Deleted member 162737

Guest
Hi Guys,

I'm 100% new in VBA world.

I am currently working on a code that automatically sends E-Mails. Code is written in VBA-Access. What I'm interested in is how can code send an image within an E-Mail, but not as an attachment.It's need to be in the body of the E-Mail. The image from E-Mail will be combined with some generated number, that Access itself provides.

Basicly, E_Mail will be information about registration: "Thank You for registration bla, bla, bla... Your generated numbor, that you need to sign is (for example) 123456789. Please sign it in bla, bla, bla..."

I have code that automaticly send E-Mail with gerated number within. But it is only text. I would like to improve it, to make it more beautiful and professional.

Can someone help me with this matter? Thank you all very much in advance!

Mare_KST
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:16
Joined
Feb 19, 2002
Messages
43,275
You didn't post your code but here is some that I use. 3/4 of the way down you see
.body = frm.txtEmailBody

the frm is a reference to the open form that called the mailing module so it is copying the text from a form field to the ody.

Code:
Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem

    .To = eMail
    .Importance = sImportance   'olImportanceHigh
    .ReadReceiptRequested = sReadReceiptRequested 'True
    .SaveSentMessageFolder = False
    '.SentOnBehalfOfName = oAccount '"ACSDEA@ACSBenefitServices.com"
    .SendUsingAccount = oAccount
    .Subject = SubjectText
    .Body = frm.txtEMailBody
    'Add the document as an attachment, you can use the .displayname property
    'to set the description that's used in the message
    .Attachments.Add Source:=FileName, Type:=olByValue
    Select Case frm.fraPrint
        Case 4
            .Display
        Case Else
            .Send
    End Select
End With
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:16
Joined
Feb 28, 2001
Messages
27,186
Hi Guys,

I'm 100% new in VBA world.

I am currently working on a code that automatically sends E-Mails. Code is written in VBA-Access. What I'm interested in is how can code send an image within an E-Mail, but not as an attachment.It's need to be in the body of the E-Mail. The image from E-Mail will be combined with some generated number, that Access itself provides.

Basicly, E_Mail will be information about registration: "Thank You for registration bla, bla, bla... Your generated numbor, that you need to sign is (for example) 123456789. Please sign it in bla, bla, bla..."

I have code that automaticly send E-Mail with gerated number within. But it is only text. I would like to improve it, to make it more beautiful and professional.

Can someone help me with this matter? Thank you all very much in advance!

Mare_KST

In the formal protocol that is SMTP, Simple Mail Transfer Protocol, there is TECHNICALLY no way to include a picture in the body of the message. You can send pictures as attachments. The body of the message is text, and when discussing "pure" SMTP, that is the end of the story.

HOWEVER, it turns out that HTML protocol can be sent through a text-only medium, so if you have a mail client that can interpret HTML (not all older mail clients do) then you can send an HTML body that can include a photo reference as part of the formatting commands. It should be noted that the photo is ALWAYS and forever an attachment. It is just that HTML allows you a choice of how & where to display it including in the body of the message rather than as an obvious attachment. It is possible for Outlook to display HTML message bodies. I am not sure about other mail clients. Modern ones should be OK. Older mail clients? No bets.

Note also that in some environments, this is disallowed behavior. For instance, if sent to a person on a military network, about 99% of the time they will have a site or group policy that disallows HTML mail. I know for an absolute fact that the U.S. Navy has such a policy because I retired from there after 28+ years. No HTML mail bodies were allowed in Navy offices.

Now one more thing. Per Gasman, who also visits other Access sites, you have cross-posted without revealing it in your post. This is (a) a violation of AWF posting policy and (b) rude. Further, he indicates that you got answers at StackOverflow. Cross posting has the potential to waste our time - particularly in this case where you got answers on another forum. If you post on another forum and don't get a response that you liked - or got no response at all - the correct practice for OUR forum is that you announce that you posted on that other forum and offer us a link to the post. That way, if you get a response from the other forum, we know to leave your post alone here and not waste our time.

While it is not fatal to your membership, multiple instances of unannounced cross-posting can result in suspension of your account. The action of deleting and then re-posting your message is also not considered proper because it looks like you KNEW you were doing wrong and tried to hide it. As a moderator, I have the authority to suspend accounts for specific periods or indefinitely in extreme cases. I will not hesitate to give you a suspension if you are caught with another unannounced cross-posting.
 

sonic8

AWF VIP
Local time
Today, 13:16
Joined
Oct 27, 2015
Messages
998
It should be noted that the photo is ALWAYS and forever an attachment.
It is not. You can put the binary data of the image in Base64 encoded form directly into the IMG tag of the HTML.
Also one should be aware that an attachment is technically just a special section in the body of the email containing an encoded text representation of the binary data. So, the boundaries between body (=text) and attachment (=binary) are very blurry to begin with.
 
D

Deleted member 162737

Guest
Crossposted at https://stackoverflow.com/questions...sent-in-body-not-attached-by-automated-e-mail with replies.
O/P had originally copied that post here verbatim in another thread, and now appears to have deleted that thread with my reply and created a new thread. :(
Hi Gasman,

you are 100% right. I'm not member only here, but on the other forums also. I wrote first on the mentioned forum and after that I copied and pasted here original text. When I realized another name was mentioned (name of onother forum), I deleted it and asked the same question again without nameing onother forum (I don't know what the policy is of this matter). You don't expect me to write the same question in seven different ways, since I'm a member of seven different forums, do you? In attachment members can find Your answer to my question. Thank You for Your time.
 

Attachments

  • Screenshot 2023-06-06 151927.png
    Screenshot 2023-06-06 151927.png
    36.2 KB · Views: 71

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:16
Joined
Feb 28, 2001
Messages
27,186
It is not. You can put the binary data of the image in Base64 encoded form directly into the IMG tag of the HTML.
Also one should be aware that an attachment is technically just a special section in the body of the email containing an encoded text representation of the binary data. So, the boundaries between body (=text) and attachment (=binary) are very blurry to begin with.

Not blurry to the U.S. Navy security filters. But you are right, the HTML protocol DOES allow you to encapsulate something. As long as it can be expressed in text, SMTP allows it as well. The question, as I stated earlier, is whether your client understands it and/or is allowed to present it. The protocol IS a text-only protocol, so you have to play tricks to get graphics included. The big question is which tricks to play.
 
D

Deleted member 162737

Guest
In the formal protocol that is SMTP, Simple Mail Transfer Protocol, there is TECHNICALLY no way to include a picture in the body of the message. You can send pictures as attachments. The body of the message is text, and when discussing "pure" SMTP, that is the end of the story.

HOWEVER, it turns out that HTML protocol can be sent through a text-only medium, so if you have a mail client that can interpret HTML (not all older mail clients do) then you can send an HTML body that can include a photo reference as part of the formatting commands. It should be noted that the photo is ALWAYS and forever an attachment. It is just that HTML allows you a choice of how & where to display it including in the body of the message rather than as an obvious attachment. It is possible for Outlook to display HTML message bodies. I am not sure about other mail clients. Modern ones should be OK. Older mail clients? No bets.

Note also that in some environments, this is disallowed behavior. For instance, if sent to a person on a military network, about 99% of the time they will have a site or group policy that disallows HTML mail. I know for an absolute fact that the U.S. Navy has such a policy because I retired from there after 28+ years. No HTML mail bodies were allowed in Navy offices.

Now one more thing. Per Gasman, who also visits other Access sites, you have cross-posted without revealing it in your post. This is (a) a violation of AWF posting policy and (b) rude. Further, he indicates that you got answers at StackOverflow. Cross posting has the potential to waste our time - particularly in this case where you got answers on another forum. If you post on another forum and don't get a response that you liked - or got no response at all - the correct practice for OUR forum is that you announce that you posted on that other forum and offer us a link to the post. That way, if you get a response from the other forum, we know to leave your post alone here and not waste our time.

While it is not fatal to your membership, multiple instances of unannounced cross-posting can result in suspension of your account. The action of deleting and then re-posting your message is also not considered proper because it looks like you KNEW you were doing wrong and tried to hide it. As a moderator, I have the authority to suspend accounts for specific periods or indefinitely in extreme cases. I will not hesitate to give you a suspension if you are caught with another unannounced cross-posting.
Hi The_Doc_Man,

thank You for Your time and detailed explanation.

1. Here is how can be done (so, it can be done):

Sub EmailDemo()
Dim strEmailAddress As String
Dim strFirstName As String
Dim strLastName As String
Dim appOutlook As Outlook.Application: Set appOutlook = New Outlook.Application
strEmailAddress = "t.axen@rivm.nl"
' strFirstName = "Thomas"
' strLastName = "Axen"
Dim mimEmail As Outlook.MailItem
Dim strPicPath As String
strPicPath = "C:\temp\carousius.jpg"
Set mimEmail = appOutlook.CreateItem(olMailItem)
With mimEmail
.To = strEmailAddress
.Subject = "Taskforce meeting"
Dim att As Outlook.Attachment
Set att = .Attachments.Add(strPicPath, 1, 0) ' set the attachment and hide it
.HTMLBody = "<html><h2>Reminder</h2><p>Lorem ipsum dolor sit amet....</p>" & _
"<img src=""carousius.jpg""></html>"
.Display
End With
End Sub

2. This is not U.S.Navy

3. I make no excuses for anything.

4. Everyone here has voluntarily and individually decided whether they want to answer me or not, they have no obgligation for that, so that's why I am not wasting someone's precious time. You are not here some organization, everyone here is an individual (to repeat once again, this is not an army here).

5. I don't agree that it's rude to ask the same questions in multiple places, especially if you're a professional. Then these basic things would not give you much time to solve, because they are basic, so to return to the previous point, it should not waste your precious time.

6. You might be right about AWF, I haven't read it.

Have a nice day and again thank You for Yout time.
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:16
Joined
Sep 21, 2011
Messages
14,305
Hi Gasman,

you are 100% right. I'm not member only here, but on the other forums also. I wrote first on the mentioned forum and after that I copied and pasted here original text. When I realized another name was mentioned (name of onother forum), I deleted it and asked the same question again without nameing onother forum (I don't know what the policy is of this matter). You don't expect me to write the same question in seven different ways, since I'm a member of seven different forums, do you? In attachment members can find Your answer to my question. Thank You for Your time.
Well in some ways your error gave away the fact that you had crossposted, and that is all we ask for, notification of where else it has been crossposted. The members over at stackoverflow also likely do not want to waste their time offering the same advice that has been offered elsewhere. At least they can look to see what has already been offered, should they choose to do so.

Please just bear it in mind for the future. Be careful, I am aware of a few users being banned from various forums for just ignoring the crossposting etiquette. Would not want it to happen to you? :)
 
D

Deleted member 162737

Guest
Well in some ways your error gave away the fact that you had crossposted, and that is all we ask for, notification of where else it has been crossposted. The members over at stackoverflow also likely do not want to waste their time offering the same advice that has been offered elsewhere. At least they can look to see what has already been offered, should they choose to do so.

Please just bear it in mind for the future. Be careful, I am aware of a few users being banned from various forums for just ignoring the crossposting etiquette. Would not want it to happen to you? :)
About wasting time I already gave my opinion to the The_Doc_Man. I thought that you and others (not all) are only asking for to help someone, how to solve a problem, of course as far as you know how. I can bet that those members who were kicked out have long since rejoined the same forum, just under a different name and a different E-Mail.
If I wanted to deal with the things you and The_Doc_Man write about, I wouldn't have put the same nick in the first place. Secondly, I wouldn't copy a 100% identical message, so neither you nor he would ever know about such a thing. But thank you for the warning, I bet we never polemicize about this topic again. ;)
 

Isaac

Lifelong Learner
Local time
Today, 04:16
Joined
Mar 14, 2017
Messages
8,777
My 2 cents is as follows:

I have specifically scrutinized and tested this issues years back and I concluded that it was some totally undocumented or random (probably has a reason somewhere, but random seeming). For example: Some people click 'attach' to an image and they know they 'attached' it, and I get their outlook email minutes later - and boom, it's embedded, not attached. Other people Paste a picture (embedded), and I get their email a few minutes later, and boom - it's Attached, not embedded.

MANY businesses put a picture in their Signature, yet my Gmail shows it to me as an Attachment - and same with Outlook.
The exact reverse happens to me all the time.

5 minutes later we can do the exact same test and have different results

Or a different person sends to me and we get different results.

Thus, even in a non-vba scenario, I believe there is something "more" - beyond what can be user-controlled - that determines whether Outlook finally renders it (on the Recipient's machine) as embedded/pasted or attached.

(in fact, even with my phone, the exact same variation occurs with the Gmail app! I know for a fact I went through the standard, full Attaching process.......yet their email client shows it embedded not attached).

The point is, IMHO, you may think you are controlling it for a time, but you really aren't certain until and unless you could see the screen of every receipient who ever opened it, in the past present and future. I would be skeptical of anyone who promises you otherwise, since the fact is, none of your code will control the receiving client email program; it makes its own decisions.

The one clear exception to everything I have said is if you actually program the htmlbody of the email..

But I don't think that was your question..
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:16
Joined
Feb 28, 2001
Messages
27,186
Hi The_Doc_Man,

thank You for Your time and detailed explanation.

1. Here is how can be done (so, it can be done):

Sub EmailDemo()
Dim strEmailAddress As String
Dim strFirstName As String
Dim strLastName As String
Dim appOutlook As Outlook.Application: Set appOutlook = New Outlook.Application
strEmailAddress = "t.axen@rivm.nl"
' strFirstName = "Thomas"
' strLastName = "Axen"
Dim mimEmail As Outlook.MailItem
Dim strPicPath As String
strPicPath = "C:\temp\carousius.jpg"
Set mimEmail = appOutlook.CreateItem(olMailItem)
With mimEmail
.To = strEmailAddress
.Subject = "Taskforce meeting"
Dim att As Outlook.Attachment
Set att = .Attachments.Add(strPicPath, 1, 0) ' set the attachment and hide it
.HTMLBody = "<html><h2>Reminder</h2><p>Lorem ipsum dolor sit amet....</p>" & _
"<img src=""carousius.jpg""></html>"
.Display
End With
End Sub

2. This is not U.S.Navy

3. I make no excuses for anything.

4. Everyone here has voluntarily and individually decided whether they want to answer me or not, they have no obgligation for that, so that's why I am not wasting someone's precious time. You are not here some organization, everyone here is an individual (to repeat once again, this is not an army here).

5. I don't agree that it's rude to ask the same questions in multiple places, especially if you're a professional. Then these basic things would not give you much time to solve, because they are basic, so to return to the previous point, it should not waste your precious time.

6. You might be right about AWF, I haven't read it.

Have a nice day and again thank You for Yout time.

I am now responding at least partly in my capacity as a moderator.

1. You were told that this could be done using HTML so thank you for some sample HTML code that others can see.
2. The comment about the Navy was an example that is often echoed by other organizations with zealous security-minded IT staff, because having something other than pure plain text embedded in a message is how hacking occurs.
3. Attitude noted.
4. You missed the point. Without proper information of cross-posting, we don't KNOW when you no longer need an answer.
5. The rudeness is to invite potentially redundant work from people who don't get paid. The only resource we have is TIME, the time it takes to research an formulate your answer. Consuming our time on a pointless exercise is the rude part.
6. At the very bottom line of this and other thread-oriented forum pages you can find links to the site's terms and rules.

The site's main members are either current or former professionals with backgrounds in various fields. Just about all of our senior members with long-term histories here have agreed at one time or another that unannounced cross-posting is a bad habit. WHY do you think that we warn you against it? We want you to get your answer, and there we can agree. We actually DON'T care if you get the answer from another site.

Where we care is when you have an adequate answer from another site but because you didn't notify us of cross-posting, we waste our time giving you an answer you already have. Oh, sure, sometimes we will jump into an answered thread if we think there is a clarification to be made. Yes, we are all nit-pickers. Comes with being a professional who takes pride in our abilities. But I am ASTOUNDED that you don't see the rudeness inherent in setting up a situation in which someone wastes their time on your behalf. If you can't see that as rude, you just didn't have the benefit of proper upbringing.

One last issue: You have been flagged in a way that we will be able to recognize in the future as being a potential time-waster. Is that a label you really want to keep?
 
D

Deleted member 162737

Guest
I am now responding at least partly in my capacity as a moderator.

1. You were told that this could be done using HTML so thank you for some sample HTML code that others can see.
2. The comment about the Navy was an example that is often echoed by other organizations with zealous security-minded IT staff, because having something other than pure plain text embedded in a message is how hacking occurs.
3. Attitude noted.
4. You missed the point. Without proper information of cross-posting, we don't KNOW when you no longer need an answer.
5. The rudeness is to invite potentially redundant work from people who don't get paid. The only resource we have is TIME, the time it takes to research an formulate your answer. Consuming our time on a pointless exercise is the rude part.
6. At the very bottom line of this and other thread-oriented forum pages you can find links to the site's terms and rules.

The site's main members are either current or former professionals with backgrounds in various fields. Just about all of our senior members with long-term histories here have agreed at one time or another that unannounced cross-posting is a bad habit. WHY do you think that we warn you against it? We want you to get your answer, and there we can agree. We actually DON'T care if you get the answer from another site.

Where we care is when you have an adequate answer from another site but because you didn't notify us of cross-posting, we waste our time giving you an answer you already have. Oh, sure, sometimes we will jump into an answered thread if we think there is a clarification to be made. Yes, we are all nit-pickers. Comes with being a professional who takes pride in our abilities. But I am ASTOUNDED that you don't see the rudeness inherent in setting up a situation in which someone wastes their time on your behalf. If you can't see that as rude, you just didn't have the benefit of proper upbringing.

One last issue: You have been flagged in a way that we will be able to recognize in the future as being a potential time-waster. Is that a label you really want to keep?
Do not take me to mean, that I withdraw from further correspondence with you and your like-minded people. I have presented my views to you and I consider that further discussion with you personally is pointless. You have reached the stage where you are now wasting my time. Regarding my upbringing do not bother, raise your own children if you have them.
And for the last issue you can respond partly in your capacity as a moderator, or maybe 3/5 as a moderator, or maybe even 7/9 and in that case do what makes you happy and fulfilled.
 
D

Deleted member 162737

Guest
My 2 cents is as follows:

I have specifically scrutinized and tested this issues years back and I concluded that it was some totally undocumented or random (probably has a reason somewhere, but random seeming). For example: Some people click 'attach' to an image and they know they 'attached' it, and I get their outlook email minutes later - and boom, it's embedded, not attached. Other people Paste a picture (embedded), and I get their email a few minutes later, and boom - it's Attached, not embedded.

MANY businesses put a picture in their Signature, yet my Gmail shows it to me as an Attachment - and same with Outlook.
The exact reverse happens to me all the time.

5 minutes later we can do the exact same test and have different results

Or a different person sends to me and we get different results.

Thus, even in a non-vba scenario, I believe there is something "more" - beyond what can be user-controlled - that determines whether Outlook finally renders it (on the Recipient's machine) as embedded/pasted or attached.

(in fact, even with my phone, the exact same variation occurs with the Gmail app! I know for a fact I went through the standard, full Attaching process.......yet their email client shows it embedded not attached).

The point is, IMHO, you may think you are controlling it for a time, but you really aren't certain until and unless you could see the screen of every receipient who ever opened it, in the past present and future. I would be skeptical of anyone who promises you otherwise, since the fact is, none of your code will control the receiving client email program; it makes its own decisions.

The one clear exception to everything I have said is if you actually program the htmlbody of the email..

But I don't think that was your question..
Hi Issac,

thank You for the answer.

I will try first with solution that Pat Hartman gave me. If that I can not achieve, I will continue with html (!?) 😁

I appreciate! Tnx
 

Jason Lee Hayes

Active member
Local time
Today, 12:16
Joined
Jul 25, 2020
Messages
175
Oh dear, not very plesent to read.

Out of interest I needed some spark plugs for my car Jaguar XJ V8 5L supercharged so I reacked out to a forum and asked how many would I need for my car. Car The attitude and response I got from a moderator was bizarre. It basically said if you know how many cylinders it has you should know how many spark plugs I need? Well, cutting a long story short he failed to recognise that a V8 engine not always have 1 spark plug per cylinder. I explained I'm not a mechanic from the outset. I felt abit thick after his comment but afew days later everyone jumped on the moderator and as a result he's no longer a moderator. I feel bad as I'm sure he know his stuff and giving his time up freely to support others I don't take likely.

I think sometimes me including can assume and respond in a way that's not entirely helpful and can be interpreted as rude but not intended. I'm contious when on forums not to assume anything and never make it personal.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:16
Joined
Feb 28, 2001
Messages
27,186
Oh dear, not very plesent to read.

Out of interest I needed some spark plugs for my car Jaguar XJ V8 5L supercharged so I reacked out to a forum and asked how many would I need for my car. Car The attitude and response I got from a moderator was bizarre. It basically said if you know how many cylinders it has you should know how many spark plugs I need? Well, cutting a long story short he failed to recognise that a V8 engine not always have 1 spark plug per cylinder. I explained I'm not a mechanic from the outset. I felt abit thick after his comment but afew days later everyone jumped on the moderator and as a result he's no longer a moderator. I feel bad as I'm sure he know his stuff and giving his time up freely to support others I don't take likely.

I think sometimes me including can assume and respond in a way that's not entirely helpful and can be interpreted as rude but not intended. I'm contious when on forums not to assume anything and never make it personal.

Actually, I would not have realized that some high-performance engines might have more than one plug to assure proper combustion. Thank you for the information. I learned something interesting today.

As to "unpleasant to read" - I actually agree with you. Having to notify a person of the site policy they just violated is never pleasant. To then have the person take an "I don't care" attitude is also sad. But the site owner, Jon, has given some of us the authority (and thus, by implication, the responsibility) to act as moderators when violations occur. If you take the job, you have to take the bad with the good.
 

Users who are viewing this thread

Top Bottom