Embedded email image shown in non-development release

I'm sending html emails through an email action program and something weird: an inline image appears on an email sent from a production deployment, but not from a local development.

professionnel_mailer.rb

class ProfessionnelMailer < ApplicationMailer

    layout 'professionnelmailer'

    def notification(professionnel)
        attachments.inline['image200.png'] = File.read("#{Rails.root}/app/assets/images/image200.png")
        @professionnel = professionnel
        mail(to: @professionnel.email, subject: "You have received a notification !")
    end    
end

notification.html.erb

<%= image_tag(attachments['image200.png'].url)%>
<h1>Hello <%= @professionnel.first_name %> !</h1>

Of course, image200.png is present locally and remotely. And the letter was received in both cases, then my Amazon AWS SES setup is correct in both environments .. Not really sure where it breaks ..

+4
source share
4 answers

For Rails> = 4.2, you must create an initializer to preview the images:

# config/initializer/preview_interceptors.rb
ActionMailer::Base.register_preview_interceptor(ActionMailer::InlinePreviewInterceptor)
0
source

, URL localhost:3000 , , IP- .

, SAS Amazon, S3 ,

.

0

, base64 , , , , - base64,

<img height="240" width="240" src="data:your_image/png;base64,/* your converted base64-string */" />

.

0
source

I had the same problem in my program. I overcame this problem using a different approach. I will send my sample code that I converted.

This is my old code:

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
String UserName = "xyz@someorg.com";
String Password = "my password";
Message.To.Add(new System.Net.Mail.MailAddress("toaddress@toadddress.com"));
Message.From = new  
System.Net.Mail.MailAddress("fromaddress@fromaddress.com");              
Message.Subject = "test subject";
Message.Body = "<img src=@'C:\\Sunset.jpg'/>";                
Message.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
smtpClient.Host = "hostname";
smtpClient.Port = 25;
smtpClient.Credentials = new 
System.Net.NetworkCredential(UserName,Password);
smtpClient.Send(message);

This is my new code:

string attachmentPath = Environment.CurrentDirectory + @"\test.png";
Attachment inline = new Attachment(attachmentPath);
inline.ContentDisposition.Inline = true;
inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
inline.ContentId = contentID;
inline.ContentType.MediaType = "image/png";
inline.ContentType.Name = Path.GetFileName(attachmentPath);

message.Attachments.Add(inline);

I think this may help you.

Link: http://www.systemnetmail.com/faq/4.4.aspx

0
source

Source: https://habr.com/ru/post/1688323/


All Articles