I am using the Grails mail plugin to send emails and I want to send images in the body of the email, not as attachment. What I want is for images to be shown in the email body itself, as in newsletters. I tried:
img style="display:block; height:100px; width:100; " alt="candle"
src="http://www.xyz.com//Candle_4.jpg">
but it is being displayed as-is.
I also tried using the wikimedia format:
[[:File:Example.jpg]]<br/>
[[Special:FilePath/Example.jpg]]
but again, both seem to link to external.
What am I doing wrong?
This is the email template I am using:
<img src="cid:springsourceInlineImage" /> Dear [username],<br/>
Thank you for shopping with us.<br/>
You have placed a new order with following details.<br/>
[details]<br/>
Happy shopping!
But, if I want to put 10 images in my template, how would I do that?
You have to do three things
Declare mail as multipart
Attach your image as inline image
Reference you inline image from your mail template
According to this mailing list thread it should work like this:
sendMail{
multipart true
to "[hidden email]"
subject "Subject goes here"
html g.render( template: '/emails/mailTemplate')
inline 'springsourceInlineImage', 'image/jpg', new File('./web-app/images/springsource.png')
}
In your template you could refer the image like this
<img src="cid:springsourceInlineImage" />
Hope that helps.
In general, most "newsletter" type emails are just HTML emails and don't in-line the images within the body of the emails. In fact, many email servers will outright reject emails that are too big, and putting the image data inside the body of the email can easily run this risk.
Instead, the way to do with this is to just have HTML emails with the images you wish to include as normal HTML image links.
Please refer to the Mail plugin documentation for more info on how to send HTML emails.
Sorry I don't have enough Stackoverflow points to leave comment on others' answers.
In #aiolos 's answer, it contains:
inline 'springsourceInlineImage', 'image/jpg', new File('./web-app/images/springsource.png')
This specifies 'image/jpg' as the output, but the file is in png format. Is this intentional?
Wikipedia provides a list of mime types: http://en.wikipedia.org/wiki/Internet_media_type#Type_image
I tried 'image/png' and it worked, so I'm not sure if setting it to 'image/jpg' makes any difference.
Related
Wondering if someone can help me...
I'm working with an application system that only accepts simple img tags for tracking, they won't take JS or GTM at all.
Is it possible to create these for events, so I can create the necessary goals within Google Analytics?
I have the event like so:
ga('send','event', 'ATS','Application', 'Application Start',0,{'nonInteration':false});
But obviously I need the img part and the UA-ID etc. I'm not great with this stuff and all the documentation I can find relates to email sends, which isn't applicable here.
Also, it's for a page load.
Many thanks for any help!
Tom
yes, you can build up your simple image tag using Measurement Protocol. You can use handy Hit builder tool to populate a necessary event url
For those reading in the future... This is what ended up working:
<img style = "width: 1%; ; "src="https://www.google-analytics.com/collect?v=1&t=event&tid=UA-XXXXXXXX-1&cid=555&ec=ATS&ea=Application&el=Application%20Start&ni=0"alt=""height="1"/>
I used the hit builder mentioned above: https://ga-dev-tools.appspot.com/hit-builder/ (thanks Дмитро Булах) to determine which parameters I needed and added the collect query to tell them to be sent to GA.
I put the cid as 555 to anonymise it (don't know if that was a good idea), then put the whole thing inside an img tag I lifted from somewhere else.
Cheers,
Tom
I tried to update my campaign html content using mailchimp api:
/campaigns/{campaign_id}/content
You can find more information about this api here: https://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/content/#
Before sending a campaign, I tried to get campaign content html, modified it and then set campaign content html using above api. I just simply use BeautifulSoup to append a new tag to content body:
content.body.append(BeautifulSoup('<p>Mailchimp is freaking shittttt</p>'))
Then, some interesting things happen, the first campaign I created, it works fine, the tag added appears in my email. But, then the sub-sequence campaigns not working anymore, the tag added not appearing.
I observed something strange on my mailchimp campaign site, even though I set campaign html content, only Plain-Text Email gets changed (HTML Source still the old version) for both working and not working campaign.
Anyone got this issue before?
I had a similar issue and I had to take a slightly different approach to solve it. According to this answer by Joel H., "MailChimp doesn't allow updating the campaign's HTML content because the campaign type is based on a template. In order to update the HTML content, the campaign has to be set to custom HTML instead of a template."
That solution didn't suit me but it led me to another solution: creating a template, creating editable content areas within that template, and then using the API to retrieve and edit the text in those content areas.
Here is an attempt at adapting my code to solve your problem. I'm using Python 3 and the mailchimp3 client.
default_footer_content = client.templates.default_content.all(template_id=TEMPLATE_ID)['sections']['SECTION_NAME']
new_footer_content = default_footer_content.replace(PLACEHOLDER, 'Mailchimp is freaking shittttt')
client.campaigns.content.update(campaign_id=CAMPAIGN_ID, data={'template': {'id': TEMPLATE_ID, 'sections': {'SECTION_NAME': new_footer_contennt}}})
Some pointers on the above code:
You can find TEMPLATE_ID with the API or simply by copying the numbers at the end of the URL when editing the template in the web interface
You define SECTION_NAME by placing 'mc:edit="SECTION NAME"' in the appropriate place in the template
I've used .replace() rather than .append() so you will need to put PLACEHOLDER or similar at the appropriate place in the template
I hope that helps, happy to modify my answer if it needs more clarification. This is my first answer on Stack Overflow so constructive criticism appreciated :)
I need send an image url to telegram without display image url and hidden url. I see a telegram bot and it's do it very well and send long message with image I'm attach this bot result image see it.
Now how can do it in my custom bot? It's possible hidden url with MARKDOWN style or any way? I want hidden image url in my text but telegram display my image. see my sample attach image.
thank you
Most of them use the dot (or some things like this character) for link description and you thought there is no link.
You can type the following line and select custom markdown:
#bold [.](http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg)
If you want to add text to your link, you need to create a bot and use this approach in the bot.
Edit:
For sending hyperlink with the bot api you can simply send html markup and using parse_mode. See telegram documents:
To use this mode, pass HTML in the parse_mode field when using sendMessage. The following tags are currently supported:
<b>bold</b>, <strong>bold</strong>
<i>italic</i>, <em>italic</em>
inline URL
inline mention of a user
<code>inline fixed-width code</code>
<pre>pre-formatted fixed-width code block</pre>
sample:
According to the Telegram API, it seems if you set disable_web_page_preview to true, you should get the result you want.
The final message should look something like this:
{
chat_id: 1235,
message: "http://your/url",
disable_web_page_preview: true,
}
EDIT:
It seems I misunderstood the question, and you actually want the image to appear by itself rather than the url by itself.
Again, as per the Telegram API you can send an image directly. But as far as I can tell, you can't use a URL to do it. You would have to upload the photo from your telegram server directly. You could use the caption property to send text with it.
Here is an example of how you might be able do this in python. You will need to tweak this to whichever language you are using, but the concept is the same.
import requests
response = requests.post(
"https://your.bot.url.com/sendPhoto",
data={
"chat_id": 1234,
"caption": "Your extra text here"
}
files={
"photo": (
"image_name.jpg",
"contents of image",
"image/jpg",
{},
)
}
)
The caption property has a limit of 200 characters, so if you want to send more characters then that, you'll have to send two messages.
You can always ask Telegram to add this type of functionality in the future
The answer is zero-width non-joiner (ZWNJ) character. ZWNJ is encoded in Unicode as U+200C ZERO WIDTH NON-JOINER (HTML , ).
HTML mode:
MARKDOWN mode:
[](https://example.com)
Update 2021:
The answer is still working but telegram doesn't let you send an empty text message that include only this character anymore, so you have to add at least one character in the whole text message. In addition you can also use the character Unicode Character 'WORD JOINER' (U+2060) instead.
You can use character as hidden character.
This might help:
It works for both:
web links
telegram links
import requests
def telegram(channel,bot,text,img):
if(text==""):text="Refer - "
r = requests.get('https://api.telegram.org/bot'+bot+'/sendMessage?chat_id=#'+channel+'&parse_mode=markdown&text='+"[]("+img+")"+text)
Use the above function. It will work perfectly. In case, there is no text and only image, it should break. So it will show a "." (dot) in those cases.
Now use the function -
telegram(your_channel_name,your_token_here,description,image_url)
To correctly send an image hosted on a website without showing any reference link, you must use the "html" parsing mode.
And in the content to send, for example, something like this (Python mode):
# We take the html address of the image.
image_address = 'https://picsum.photos/100.jpg'
# The unicode character to prevent the words from
# being separated, in this case, we take advantage
# of it so that the Telegram API accepts it and
# incidentally so that it does not take up space
# when including text in the message.
word_joiner = '⁠'
# This would be the final pattern.
html_pattern = f'{word_joiner}'
With HTML parse mode. Keep empty space between the opening and closing tag.
I have many dynamically generated pages, made by the same PHP file, and I'd like the comments that are being submitted to the user's wall have a different title and summary, considering the page they were sent from. Do I need to dynamically generate the meta tags, or is there a way to embed the title and summary in the comments widget script itself?
You will need to do the first thing...dynamically generate the og tag in the head of the document. They must be set that way when sending the HTML response to the browser. They cannot be successfully updated clientside as Facebook linter only looks at the response stream.
I have a text area in which I am trying to add youtube embed code and other HTML tags. $this->input->post is converting the <iframe> tags to < and > respectively but not the <h1> and <h2> tags.
Any idea how I can store these values?
If you only have a small number of forms that you need to allow iframes in, I would just write a function to restore the iframe (while validating that it's a valid YouTube embed code).
You can also turn off global_xss_filtering in your config (or not implement it if you're using it), but that's not the ideal solution (turning off all of your security to get one thing to work is generally a horrible idea).
$config['global_xss_filtering'] = FALSE;
To see all of the tags that get filtered out, look in the CI_Input class and search for the '$naughty' variable. You'll see a pipe-delimited list (don't change anything in this class).
Why don't you avoid CIs auto sanitizing and use something like htmlspecialchars($_POST['var']); ? Or make a helper function for sanitizing youtube urls...
Or you could either just ask for the video ID code or parse the code from what you are getting.
This would let you use both the URL or the embed code.
Also storing just the ID takes less space in you database, and you could write a helper function to output the embed code/url.
In this case, use $_POST instead of $this->input->post to get the original text area value, and then use HTML Purifier to clean the contents without losing the <iframe> tag you want.
You will need to check HTML Purifier documentation for details. Please, check this specific documentation page about "Embedding YouTube Videos".