How to set website logo image on signup mail in rails?

473 Views Asked by At

I am using rails 5 when user is registered in my website i am sending an email for him for account approval.I want to set website logo with email. How we implement this in rails mailer view file enter image description here

Html for mail template

<!DOCTYPE HTML>
<html>
<title>nytApp Email</title>
    <head>
    </head>
    <body style="font-family: 'arial', sans-serif !important;   font-size: 14px;   line-height: 20px;  color:#3e3e3e; background-color: #f5f5f5; font-weight: 300;">
        <!-- Container Table -->
        <table cellpadding="0" cellspacing="0" border="0" width="100%">
            <tr>
                <td>
                    <table cellpadding="0" cellspacing="0" width="640" style="margin:0 auto; background:#fff;">
                        <tr>
                            <td style="border: 1px solid #f5cd8f;">
                                <table cellpadding="0" cellspacing="0" border="0" width="100%">
                                    <tr>
                                        <td style="padding: 25px 15px 20px; border-bottom: 1px solid #f5cd8f;">
                                            <table  align="center" cellpadding="0" cellspacing="0" border="0" width="100%">
                                                <tr>
                                                    <td><%= image_path('logo.png')%></td>
                                                    <td>
                                                        <table cellpadding="0" cellspacing="0" border="0" width="100%" style="font-weight: bold; font-size: 16px;">
                                                            <tr>
                                                                <td style="color: #ff5e00; font-weight: 300; font-size: 20px;">Welcome to Nytapp</td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 0 15px 20px;">
                                            <table  align="center" cellpadding="0" cellspacing="0" border="0" width="100%">
                                                <tr><td height="10"></td></tr>
                                                <tr>
                                                    <td>Thank you for signing up as Events Promoter!</td>
                                                </tr>
                                                <tr><td height="25"></td></tr>
                                                <tr>
                                                    <td>You are ready to start posting your parties for free. Login to the portal by clicking on the link below:</td>
                                                </tr>
                                                <tr><td height="10"></td></tr>
                                                <tr>
                                                    <td><a href="https://night-app.herokuapp.com/admin" style="color: #00a8ff;">https://nytapp.com</a></td>
                                                </tr>
                                                <tr><td height="10"></td></tr>
                                                <tr>
                                                    <td>If the above URL does not work try copying and pasting it into your browser.</td>
                                                </tr>
                                                <tr><td height="8"></td></tr>
                                                <tr>
                                                    <td>If you encounter any problem, please contact us at <a href="mailto:[email protected]" style="color: #333; font-weight: bold; text-decoration: none;">[email protected]</a></td>
                                                </tr>
                                                <tr><td height="25"></td></tr>
                                                <tr>
                                                    <td>Thank you,</td>
                                                </tr>
                                                <tr>
                                                    <td>The Nytapp team</td>
                                                </tr>
                                                <tr><td height="30"></td></tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="border-top: 1px solid #f5cd8f; vertical-align: middle;  padding: 10px 15px;">
                                            <table cellpadding="0" cellspacing="0" border="0" width="100%">
                                                <tr>
                                                    <td>
                                                        <%= image_path('logo.png') %>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>
2

There are 2 best solutions below

0
Nitin On

In mailer you can't give relative path. So try upload your logo somewhere in cloud like s3 and give complete logo url in image tag source.

You can also use asset_url it compute complete url.

<%= image_tag asset_url('logo.png') %>
0
VK29 On

In your html.erb file which is suppose to be send as mail you need to wrtte something like this.....

<img src=" <%= Rails.application.secrets.host + "" +  asset_path("sd_logo.png") %>"