Best way to send photo inside mail Django - html

What is the best way to attach my website logo inside activation mail? I tried to do something like this:
#lru_cache()
def logo_data():
with open('templates/authentication/logo.png', 'rb') as f:
logo_data = f.read()
logo = MIMEImage(logo_data)
logo.add_header('Content-ID', '<logo>')
return logo
and then:
email=EmailMessage(subject=email_subject, body=email_body, from_email=settings.EMAIL_FROM_USER, to=[user.email])
email.attach(logo_data())
email.content_subtype='html'
email.send()
In my html file it looks like this:
<img src="cid:logo" style="width: 242px; height: 88px;"/>
but it doesn't work. The photo is actually added to the mail in attachments, but the <img> tag is empty and looks just like this:
What is wrong? I read also that attaching photos to email is not recommended because mail gets cause of that extra spam points. What is the best way to do this? Can I send my png logo without attaching it into attachments?
EDIT
I tried to add url (to my photo on google drive) like this <img scr="url"> but these properties disappear inside mail

You can use a CDN, like S3 or Google Cloud bucket to upload the image and add the url of the image in your <img src="URL"> tag.

Related

Wordpress/HTML: Image source is not working correctly

I am using an email template builder (pro.beefree.io) in which I have put some images, including my company logo. I then export the html from pro.beefree.io and paste it in the code as body for the wp_mail function. Here is a snippet of the html code containing the logo image:
<div class="alignment" align="center" style="line-height:10px"><img class="big" src="https://d15k2d11r6t6rl.cloudfront.net/public/users/Integrators/BeeProAgency/868180_852318/logo-image.png" style="display: block; height: auto; border: 0; width: 440px; max-width: 100%;" width="440"></div>
Issues
This works and the email is sent with the image. However, when a user opens the email they get a "Externally linked resources in the message have been blocked" warning and have to "allow" to be able to view the images. Is there a way to fix this so the images show up immediately? The problem occurs on at least gmail, outlook and roundcube (our server email).
I want the images stored on our own server for safety if the company removes our images or something else happens to them. I tried to place them inside a folder and put src to it as follows:
src = "https://website.com/images/logo-image.png"
We used similar path for images on the website which works fine. However, in the email which is sent via wp_mail no images show up, there is just a placeholder image symbol instead. How can I put images in my own folders and link them properly?

Integrate qrcode as a wallpaper

I'm using the following library to generate QRCodes: https://marcoagner.github.io/Flask-QRcode/
I would like to give the user the option to download this QR and set it as a wallpaper. The problem is that when I generate the qrcode, if you download the image via pressing the image for a few seconds, you only download the QRCode and when you go to your "camera roll" and you set it as a wallpaper it's something like this:
My question is: How can I set white borders around the QRcode so when the user downloads the image he/she can set it as a correct wallpaper?
This is my code:
<center><img src="{{ qrcode("http://myherokuapp.com" + url_for('view', useraid=useraid),box_size=4 )}}"></center>
Thank you in advance.
I've just realized this library has a border option, which is exactly I was looking for, so I made:
<center><img src="{{ qrcode("http://myherokuapp.com" + url_for('view', useraid=useraid),box_size=4, border=50 )}}"></center>

HTML img - passing file name as parameter

I would like a HTML to get an image file name as a parameter from another page and display that image. I only know a bit of HTML. I don't know PHP etc.
I have a website which has several HTML pages. I want to write an "image container" page which will be called from other pages. The other pages will pass it a bitmap file name and the container page will display that image.
Ideally the container page should be getting few other parameter like the width and height of the image.
In showimage.html:
Instead of this:
<img src="bitmaps/test.jpg" height="200">
Have something like this:
<img src="{parameter 1}" height="{parameter 2}">
And the calling page will call showimage.html with "bitmaps/test.jpg" and "200".

ASP.NET MVC Img tag not loading image when loading path from database

I am attempting to make a photo gallery asp.net MVC website, and part of that involves the setting of the src to a local folder that contains images.
#model MyProj.Models.PhotoIndexViewModel
<div class="row" id="tableSearch">
#foreach (MyProj.Models.VideoModel photo in Model.PImgList)
{
<div class="col-sm-3 thumbnail">
#Html.DisplayFor(model => photo.Title)
<a href=#Url.Action("View", new { id = photo.Id })>
<img class="img-responsive"src="#Url.Content(photo.ThumbNailPrev)" alt=#photo.Id /></a>
#Html.HiddenFor(m => m.searchTerm)
#Html.Partial("_Tags", photo)
</div>
}
</div>
The ThumbNailPrev is "~/Pics/.jpg", which relates to a folder in the main part of the project. The issue is that the image does not appear. When I check the image using inspector is says it isn't found at /Pics/(photoid)/jpg. I don't understand why it is doing this, as my pics and the image itself are present at that location. I have also made sure to include the folder in my project, but it still doesn't seem to find the image.
UPDATE:
I just tried something and confirmed it is something to do with the way I'm calling the path from the database. As if I hard code the EXACT same string as the one in the database it works. The question now is why does that work?
For want of a letter..
I finally determined the problem, and it was a pretty dumb one. In code I am saving a jpEg image, but calling it via jpg. After changing the .jpg to .jpeg in the view everything works... If you are having a similar problem, check and make certain the file extension is correct.

Image hyperlink using a value stored in database

I am trying to allow the user to link their facebook, twitter etc and have an image for the corresponding link appear which will take them to the link stored in the database.
The problem is, instead of giving me something like "www.facebook.com" it is giving me "http://localhost:60619/User/www.facebook.com"
right now I am using to get this.
<a href="#Url.Action(#Model.Facebook)">
<img src="#Url.Content("~/Content/images/Facebook.gif")" alt="Facebook" /></a>
The Url.Action has managed to remove /User/Profile/www.facebook.com and replace is with /user/www.facebook.com but I can't get it to be just "www.facebook.com".
Edit: I have this figured out but thank you for the help! I just needed to add validation so that the user either enters http:// at the beginning or I will have it added on manually before it is stored.
#{
var url = #Model.Facebook.Split('/');
...
}