Why is my mail being marked as spam when send via Mvc.Mailer? - email

I am using the Nuget Package Mvc.Mailer to send e-mail to my clients. I followed this guide and I'm encountering one really annoying thing. My sent e-mails are always sent to spam. Here's what my code looks like:
UserMailer:
public virtual MvcMailMessage Authenticatie(User user, string email)
{
ViewBag.User = user;
ViewBag.Email = email;
return Populate(x =>
{
x.Subject = "Your registration at Example";
x.ViewName = "Registration";
x.IsBodyHtml = true;
x.From = "Name <noreply#example.com>";
x.To.Add(email);
});
}
Registration.cshtml:
using Mvc.Mailer
<div>
<p style="display: none">Stuff in my email</p>
<h1 style="background: #e68425; text-align: center; color: white; margin: 0px; padding: 10px;">
A bunch of HTML
</h1>
<div style="background: #cf7721; text-align: center; padding: 10px;">
<h3 style="margin: 0px;">Activate account</h3>
</div>
<div>
<p>Dear client,</p>
<p>
Thanks for bla bla bla... And more stuff.
</p>
<table>
<tr>
<td>Login:</td>
<td>#ViewBag.User.Login</td>
</tr>
<tr>
<td>Activatiecode:</td>
<td>#ViewBag.User.Activation</td>
</tr>
</table>
</div>
Web.config:
<mailSettings>
<!-- Method#1: Configure smtp server credentials -->
<smtp from="Example <noreply##example.com>">
<network enableSsl="false" host="mail.#example.com" port="25" userName="noreply#example.com" password="xxx" />
</smtp>
</mailSettings>
What we have tried
Sending our e-mails via the standard way, with the SmtpClient. This mail didn't go to spam.
Setting x.From to a better name.
Different content types
x.IsBodyHtml = true
Sending an e-mail from our e-mail client (same address). This mail didn't go to spam.
Questions
Could our e-mail be filtered by excessive use of html?
Has anybody encountered this problem before, using this Nuget package?
How can I stop my e-mails from going to spam?
Above all: why are they going to spam?

Try to check all hyperlinks in template. It was just the word "email" in one of my Url.Action for becoming junk.

Related

SendGrid API Dynamic - can't get Unsubscribe to work

I just set-up a dynamic email with sendgrid and am using the API to fill it out based on my customer data.
I've gotten everything to work except the unsubscribe part.
I have an unsubscribe block at the bottom of my email. In the code editor, the code looks like this:
<div data-role="module-unsubscribe" class="module" role="module" data-type="unsubscribe" style="color:#444444; font-size:12px; line-height:20px; padding:16px 16px 16px 16px; text-align:center;" data-muid="67cd14f7-ddbf-421a-a070-57b3b3e6ccac"><p style="font-size:12px; line-height:20px;"><a class="Unsubscribe--unsubscribeLink" href="{{unsubscribe}}" target="_blank" style="">Unsubscribe</a></p></div></td>
I didn't edit the code, that's just how it came. But when I send the email (test or otherwise), the unsubscribe is not a link. Do I need to pass something for {{unsubscribe}} in the API request? If so, what would I pass?
Thanks for your help!
When you send an email with unsubscribe links, you need to include the unsubscribe group in the API request.
For example:
client
.send({
to: "hello#example.com",
from: "me#example.org",
templateId: "YOUR_TEMPLATE_ID",
dynamicTemplateData: { ... },
asm: {
groupId: "YOUR_UNSUBSCRIBE_GROUP_ID"
}
})
Make sure the asm key is in the root object, not in personalizations.
<div data-role="module-unsubscribe" class="module" role="module" data-type="unsubscribe" style="color:#444444; font-size:12px; line-height:20px; padding:16px 16px 16px 16px; text-align:center;" data-muid="67cd14f7-ddbf-421a-a070-57b3b3e6ccac"><p style="font-size:12px; line-height:20px;"><a class="Unsubscribe--unsubscribeLink" href="{{unsubscribe}}" target="_blank" style="">Unsubscribe</a></p></div></td>

Magento 2 : Change email content based on shipping method in email template

I need to change the email content based on shipping method. there are two type of shipping method one is in store pickup and one is delivery to user location.
For both case content of email template is like :
Thank you for your order from XYZ. Once your package ships we will send you a tracking number. You can check the status of your order by logging into your account.
I don't want this line "Once your package ships we will send you a tracking number." for in store pickup and change this line with some other info.
My Email template sample like :
{{template config_path="design/email/header_template"}}
<table>
<tr class="email-intro">
<td>
<p class="greeting">{{trans "%customer_name," customer_name=$order_data.customer_name}}</p>
<p>
{{trans "Thank you for your order from %store_name." store_name=$store.frontend_name}}
{{trans "Once your package ships we will send you a tracking number."}}
{{trans 'You can check the status of your order by logging into your account.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}
</p>
<p>
{{trans 'If you have questions about your order, you can email us at %store_email' store_email=$store_email |raw}}{{depend store_phone}} {{trans 'or call us at %store_phone' store_phone=$store_phone |raw}}{{/depend}}.
{{depend store_hours}}
{{trans 'Our hours are <span class="no-link">%store_hours</span>.' store_hours=$store_hours |raw}}
{{/depend}}
</p>
</td>
</tr>
<tr class="email-summary">
<td>
<h1>{{trans 'Your Order <span class="no-link">#%increment_id</span>' increment_id=$order.increment_id |raw}}</h1>
<p>{{trans 'Placed on <span class="no-link">%created_at</span>' created_at=$created_at_formatted |raw}}</p>
</td>
</tr>
<tr class="email-information">
<td>
{{depend order_data.email_customer_note}}
<table class="message-info">
<tr>
<td>
{{var order_data.email_customer_note|escape|nl2br}}
</td>
</tr>
</table>
{{/depend}}
<table class="order-details">
<tr>
<td class="address-details">
<h3>{{trans "Billing Info"}}</h3>
<p>{{var formattedBillingAddress|raw}}</p>
</td>
{{depend order_data.is_not_virtual}}
<td class="address-details">
<h3>{{trans "Shipping Info"}}</h3>
<p>{{var formattedShippingAddress|raw}}</p>
</td>
{{/depend}}
</tr>
<tr>
<td class="method-info">
<h3>{{trans "Payment Method"}}</h3>
{{var payment_html|raw}}
</td>
{{depend order_data.is_not_virtual}}
<td class="method-info">
<h3>{{trans "Shipping Method"}}</h3>
<p>{{var order.shipping_description}}</p>
{{if shipping_msg}}
<p>{{var shipping_msg}}</p>
{{/if}}
</td>
{{/depend}}
</tr>
</table>
{{layout handle="sales_email_order_items" order_id=$order_id area="frontend"}}
</td>
</tr>
</table>
{{template config_path="design/email/footer_template"}}
I see the email for In store Pickup {{var order.shipping_description}} value is like "In-Store Pickup Delivery - "
And For Second One Value is like "Flat Rate - Fixed".
Please help like which condition i need to put for the content changes.
Thanks
You can achieve this by adding your logic to an observer.
Create basic module
registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Vendor_Module',
__DIR__
);
module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="1.0.0"/>
</config>
Register an observer for when email templates are loaded
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="email_order_set_template_vars_before">
<observer name="name_of_observer" instance="Vendor\Module\Observer\AddVariable" />
</event>
</config>
In your Observer app\code\Vendor\Module\Observer\AddVariable.php
<?php
namespace Vendor\Module\Observer;
use Magento\Sales\Model\Order;
use Magento\Framework\Event\ObserverInterface;
class AddVariable implements ObserverInterface
{
protected $order;
public function __construct(
Order $order
) {
$this->order= $order;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** #var \Magento\Framework\App\Action\Action $controller */
$transport = $observer->getEvent()->getTransport();
if($transport->getOrder() != null)
{
$order = $this->order->load($transport->getOrder()->getId());
$shipping_method = $order->getShippingAddress()->getShippingMethod();
$transport['variable'] = /*some logic ... */
}
}
}
$transport['variable'] adds the variable to your data. You can call it like any other variable from your template and assign as many as you like.

VueJS plugin rendering problems. Vue Formulate

So i am not profeccional in vueJs that`s why if you need some more additional information just write in coments i will try to provide it...
This is the way that i intalling this plugin
import VueFormulate from '#braid/vue-formulate';
Vue.use(VueFormulate);
and in my template where i want to use this plugin
<FormulateInput
type="email"
name="email"
label="Enter your email address"
help="We’ll send you an email when your ice cream is ready"
validation="required|email"
/>
but on browser page there is nothing and what i see in rendered page tree
<formulateinput
type="email"
name="email"
label="Enter your email address"
help="We’ll send you an email when your ice cream is ready"
validation="required|email">
</formulateinput>
So as i can see it is not rendered.
A little interting thing. When component where i whant to use plugin mounted then output in console plugin object, and it is exits
mounted() {
console.log(VueFormulate);
}
screen from console
can you please help me to find what i miss? :3
The main problem was in template tags.
And VueFormulate component in my template must be lower-cased, hyphen separated and with a closing tag
<formulate-input
type="email"
name="email"
label="Enter your email address"
help="We’ll send you an email when your ice cream is ready"
validation="required|email"
></formulate-input>
instead of
<FormulateInput
type="email"
name="email"
label="Enter your email address"
help="We’ll send you an email when your ice cream is ready"
validation="required|email"
/>
More information about syntax style:
https://v2.vuejs.org/v2/style-guide/#Component-name-casing-in-templates-strongly-recommended
try this working code:
App.js
<template>
<div id="app">
<FormulateInput
type="email"
name="email"
label="Enter your email address"
help="We’ll send you an email when your ice cream is ready"
validation="required|email"
/></div>
</template>
<script>
import Vue from "vue";
import VueFormulate from '#braid/vue-formulate';
Vue.use(VueFormulate);
export default {
name: "App",
};
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
and Main.js must be like this:
import Vue from "vue";
import App from "./App.vue";
new Vue({
render: h => h(App)
}).$mount("#app");
It actually render component but without style! if you want to use component style, write :
#import '../node_modules/#braid/vue-formulate/themes/snow/snow.scss';
in your scss style file or import https://github.com/wearebraid/vue-formulate/blob/master/dist/snow.min.css in your project!

Issue of table break in outlook 2010

I have strange issue in my email when it is viewed in outlook 2010.
The source for the email is as follows,
<html>
<head>
<title>Testing</title>
</head>
<body style="background:green;border:100px solid red">
<table style="border:20px solid blue; width:600px;" align="center">
<tr>
<td>
</td>
</tr>
<tr>
<td style="background:#DDD;">
<span>0</span><br /><span>1</span><br /><span>2</span><br /><span>3</span><br /><span>4</span><br /><span>5</span><br /><span>6</span><br /><span>7</span><br /><span>8</span><br /><span>9</span><br /><span>10</span><br
/><span>11</span><br /><span>12</span><br /><span>13</span><br /><span>14</span><br /><span>15</span><br /><span>16</span><br /><span>17</span><br /><span>18</span><br /><span>19</span><br /><span>20</span><br /><span>21</span><br /><span>22</span><br /><span>23</span><br /><span>24</span><br
/><span>25</span><br /><span>26</span><br /><span>27</span><br /><span>28</span><br /><span>29</span><br /><span>30</span><br /><span>31</span><br /><span>32</span><br /><span>33</span><br /><span>34</span><br /><span>35</span><br /><span>36</span><br /><span>37</span><br /><span>38</span><br
/><span>39</span><br /><span>40</span><br /><span>41</span><br /><span>42</span><br /><span>43</span><br /><span>44</span><br /><span>45</span><br /><span>46</span><br /><span>47</span><br /><span>48</span><br /><span>49</span><br /><span>50</span><br /><span>51</span><br /><span>52</span><br
/><span>53</span><br /><span>54</span><br /><span>55</span><br /><span>56</span><br /><span>57</span><br /><span>58</span><br /><span>59</span><br /><span>60</span><br /><span>61</span><br /><span>62</span><br /><span>63</span><br /><span>64</span><br /><span>65</span><br /><span>66</span><br
/><span>67</span><br /><span>68</span><br /><span>69</span><br /><span>70</span><br /><span>71</span><br /><span>72</span><br /><span>73</span><br /><span>74</span><br /><span>75</span><br /><span>76</span><br /><span>77</span><br /><span>78</span><br /><span>79</span><br /><span>80</span><br
/><span>81</span><br /><span>82</span><span>85</span><br /><span>86</span><br /><span>87</span><br /><span>88</span><br /><span>89</span><br /><span>90</span><br /><span>91</span><br /><span>92</span><br /><span>93</span><br /><span>94</span><br /><span>95</span><br /><span>96</span><br
/><span>97</span><br /><span>98</span><br /><span>99</span><br /><span>100</span>
</td>
</tr>
</table>
</body>
</html>
And the email looks in outlook 2010 is as follows,
http://postimg.org/image/dpinwd9l7
In the image, you can see there is breaking of table and also border is breaked. I don't know why it is happening.
Please help me to get rid of this issue.
I think what is happening it that you are over 1800px in a single column.
You can read more about it here:
The best answer is to break it up into two tables stacked on top of each other.

Magento Contact Form - been receiving email from myself

For some reason, when a customer submit the contact form, it appears in my gmail that the email was sent from myself, not from my customer.
Please check out the pictures so you know what I am talking about.
http://i.stack.imgur.com/QsACc.jpg
This image shows the email came from myself
http://i.stack.imgur.com/nghG2.jpg
Look at the arrow, this is what I see every email that comes from the contact from. Same name, same title.
This is really annoying because when many people use this, there is no way I can tell which one is which.
This is my contact page: meome.vn/lien-he
There might be some code to put in the email template that I don't know. Anyway if anyone knows how to fix this, please help me. I really appreciate it.
Did you check your email configuration in the backend.
Admin -> System -> configuration -> Store Email Addressess and
Admin -> System -> configuration -> Contacts -> Email options
Technically, this is a duplicate of Change 'From' field of magento contact form email to the sender but I put a complete and thorough answer here. A simple core hack is one answer provided there.
I am determined to not hack core files, so I solved this problem by making a custom controller. I read up and it seemed easy enough... and also no extensions on the market offer the goals I set out to accomplish: 1) have customer email & name on the From; 2) simple human input for anti spam; and 3) a couple custom fields, 3 of which are actually product attributes.
The files to accomplish this are:
$ find -type f
./Cycleworks/Cycleworks_ContactExtended.xml
./Cycleworks/ContactExtended/controllers/IndexController.php
./Cycleworks/ContactExtended/Helper/Data.php
./Cycleworks/ContactExtended/etc/config.xml
And now for the files themselves... The first XML file tells Magento about your custom override.
// copy this to app/etc/modules/
./Cycleworks/Cycleworks_ContactExtended.xml
<?xml version="1.0"?>
<config>
<modules>
<Cycleworks_ContactExtended>
<active>true</active>
<codePool>local</codePool>
</Cycleworks_ContactExtended>
</modules>
</config>
The remainder of the files go in app/code/local/. Below, I copied the postAction() function from the original controller and then added my code at the top and then made the one change in ->sendTransactional()
./Cycleworks/ContactExtended/controllers/IndexController.php
<?php
require_once 'Mage/Contacts/controllers/IndexController.php';
class Cycleworks_ContactExtended_IndexController extends Mage_Contacts_IndexController
{
public function postAction()
{
$post = $this->getRequest()->getPost();
if ( $post ) {
if( stripos( $post["people"],"tires") ===FALSE ){
Mage::getSingleton('customer/session')->addError("Please correctly answer the question to confirm you are human.<br>\"".$this->getRequest()->getPost("people")."\" is not correct.");
$this->_redirect('*/*/');
return;
}
$extras=Array( "bike_year","bike_make","bike_model","bike_model_ext" );
foreach($extras as $field) {
if( $post[$field] == "empty" )
$post[$field]= "----";
}
$comment = $post['comment']."\nMage::getStoreConfig(self::XML_PATH_EMAIL_SENDER)=\n'".Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER)."'";
$post['comment']= nl2br($comment);
$translate = Mage::getSingleton('core/translate');
/* #var $translate Mage_Core_Model_Translate */
$translate->setTranslateInline(false);
try {
...
...
...
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
->setReplyTo($post['email'])
->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
array( 'name'=>$post['name'],'email'=> $post['email'] ), // Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), //
Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
null,
array('data' => $postObject)
);
...
...
...
}
}
Nice and empty shell. And yes, these all have opening <?php tags but not closing ones??
./Cycleworks/ContactExtended/Helper/Data.php
<?php
class Cycleworks_ContactExtended_Helper_Data extends Mage_Core_Helper_Abstract
{
}
And the XML in the custom module:
./Cycleworks/ContactExtended/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Cycleworks_ContactExtended>
<version>0.0.01</version>
</Cycleworks_ContactExtended>
</modules>
<frontend>
<routers>
<contacts>
<args>
<modules>
<Cycleworks_ContactExtended before="Mage_Contacts">Cycleworks_ContactExtended</Cycleworks_ContactExtended>
</modules>
</args>
</contacts>
</routers>
</frontend>
<global>
<helpers>
<contactextended>
<class>Cycleworks_ContactExtended_Helper</class>
</contactextended>
</helpers>
</global>
</config>
That's all the backend. As for the form itself, I added this code to form.phtml below the comments block and above the closing </ul> tag. For most people this file is in app/code/design/frontend/default/default/template/contacts. Since I have a TM template that I purchased, mine is in default/a034/template/contacts
<?php
$confirm_people_question="Motorcycles have two of these and rhymes with plires"; // CKCK form anti-spam
?>
<li>
<label for="people" class="required"><em>*</em><?php echo $confirm_people_question ?></label>
<div class="input-box">
<input name="people" id="people" title="Please confirm you are people" value="" class="required-entry input-text" type="text" />
</div>
</li>
<?php
// from http://www.sharpdotinc.com/mdost/2009/04/06/magento-getting-product-attributes-values-and-labels/
$wanted=Array("make","model","engine_size"); // note that each attribute needs to be searchable
$attributes = Mage::getModel('catalogsearch/advanced')->getAttributes(); // $productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');
$attributeArray=array();
foreach($attributes as $a){
if( in_array( $a->getAttributeCode(), $wanted) ){
foreach($a->getSource()->getAllOptions(false) as $option){
$attributeArray[$a->getAttributeCode()][$option['value']] = $option['label'];
}
}
}
?>
<li>
<div class="ymm">
<label for="bike_year">Year</label><br>
<select id="year" name="bike_year">
<option value="empty"></option>
<? for( $idx=date("Y"); $idx >= 1985; $idx-- )
echo " <option value=\"$idx\">$idx</option>\n";
?>
</select>
</div>
<div class="ymm">
<label for="bike_make">Make</label><br>
<select id="make" name="bike_make">
<option value="empty"></option>
<? foreach( $attributeArray['make'] as $id => $brand )
echo " <option value=\"$brand\">$brand</option>\n";
?>
</select>
</div>
<div class="ymm">
<label for="bike_model">Model</label><br>
<select id="model" name="bike_model">
<option value="empty"></option>
<? foreach( $attributeArray['model'] as $id => $model )
echo " <option value=\"$model\">$model</option>\n";
?>
</select>
</div>
<div class="ymm">
<label for="bike_model_ext">More</label>
<div class="input-box">
<input type="text" size="15" value="" id="model_ext" name="bike_model_ext" class="input-text">
</div>
</div>
</li>
I almost forgot, the final key to the puzzle is the mail template in the admin area: System - Transactional Emails. Find your HTML contact template (or make a new one and do not convert it to plain text) and this is what I've got:
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table>
<tr><td>Name</td><td>{{var data.name}}</td></tr>
<tr><td>E-mail</td><td>{{var data.email}}</td></tr>
<tr><td>Telephone</td><td>{{var data.telephone}}</td></tr>
</table>
<P>
<fieldset><legend>Subject: {{var data.subject}}</legend>
{{var data.comment}}
</fieldset>
Bike info: {{var data.bike_year}} {{var data.bike_make}} {{var data.bike_model}} {{var data.bike_model_ext}}
</div>
</body>
I never really thought I would have made my own custom module, but I followed the recipes I found on here and elsewhere and put this together. It also behaves correctly when the capcha fails. I did try to research how to give the option to CC the customer with their own contact, but I couldn't find anything.
Later, I tried to make a custom module to allow an alternate admin notification email template for new orders but the knowledge I had learned from above wasn't enough. :P So my knowledge and comfort with Magento is perhaps above "dangerous hack", but I still have a long way to go.