capybara-email email after click from email - email

In use: Rails 4, RSpec 3, capybara, capybara-email.
After create object user receive email in which present link. If user click this link, another user receive another email.
So how I can test two emails in same test?
My sample:
scenario 'Sample test', js: true do
my_page.create_object(name: 'example')
open_email(user.email)
expect(current_email).to have_content('example')
current_email.click_link('ACCEPT')
# there will be request to server and
# if all is ok, sending next email to same user
# how I can open next email?
end

Solved in next way,
scenario 'Sample test', js: true do
my_page.create_object(name: 'example')
open_email(user.email)
expect(current_email).to have_content('example')
clear_emails
visit path_from_link_path
open_email(user.email)
expect(current_email).to have_content('other text')
clear_emails
end
Maybe someone have better solution, please share it.

Related

How can I add unsubscribe links to my emails when sending via sendgrid/mail

I'm sending emails using: https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail
I have not been able to find out HOW I can add the Unsubscribe equivalent. This is documented in here: https://sendgrid.com/docs/Classroom/Basics/Marketing_Campaigns/unsubscribe_groups.html#-Using-a-Custom-Unsubscribe-Link
On the website, you just use a shortcode [Unsubscribe], this does not work when sending emails via the sendgrid/mail package.
One tip that would have saved me an hour or two is that:
It's possible to send the following in the api json along with other stuff:
"asm":{
"group_id":123,
"groups_to_display": [123],
}
then the following variables become available to use within the template:
<%asm_group_unsubscribe_raw_url%>
<%asm_preferences_raw_url%>
If you want to keep things simple don't include the following variable as it fiddles with too many things (this wasn't obvious from the documentation so obviously I did so and wasted time :( ):
"tracking_settings": {
"subscription_tracking": {
"enable": true,
"substitution_tag": "[unsubscribe_url]"
}
}
Just use them in their raw format and you shall be fine.
Since you're sending using code, it's a "transactional" type of message. You'll want to either turn on the Subscription Tracking filter at the account level (via [UI](subscription tracking setting) or API), or turn it on as you send the message, as part of the mail/send API call, under tracking_settings.
It's important to note that you can't mix those. If you define anything in the mail/send API call, you'll need to define everything for Subscription Tracking in that call. SendGrid won't look at some settings at the mail level, and some at the account level.
Most users will just set it at the account level. There, you can customize the HTML & Text of the Unsubscribe footer, customize the HTML of the landing page, or redirect landing to a URL of your choosing, which will send the recipient there with ?email=test#domain.com in the URL string for your system to catch. You can also define the "replacement tag" like [%unsubscribe%], so that you can place the URL wherever you want within your HTML.
https://app.sendgrid.com/ > Suppressions > Unsubscribe Groups > Create New Group
Note down group_id/ids. e.g 123 (Only number !Not string)
Send email using node.js
const sgMail = require('#sendgrid/mail');
sgMail.setApiKey(SENDGRID_API_KEY);
const tags = { invitedBy : Alex }
const msg = {
to: email,
from: { "email": SENDER_EMAIL,
"name": SENDER_NAME
},
templateId: TEMPLATE_ID,
dynamic_template_data: {
Sender_Name: name,
...tags
},
asm: {
group_id: 123,
groups_to_display: [
123
],
},
};
await sgMail.send(msg);
The best approach is to use Group Unsubscribes.
First create a group in Sendgrid:
Groups > Unsubscribe Groups > Create a group
Next, insert a module into the Sendgrid template that creates specific tags in your email, which are populated when you make an API request
Go to your template
Insert an unsubscribe module in an HTML block
Save
Finally make an API request and specify the group created in step 1:
"asm":{
"group_id":544,
"groups_to_display": [544, 788],
}
These will be inserted into the module mentioned in step 2 when the email is sent.
Unfortunately Sendgrid unsubscribe links are not as straightforward as they could be. They are explained in more detail here
The easiest way is to do this via the SendGrid GUI.
Go to Settings -> Tracking -> Subscription Tracking

If/Else Loop and Auto Email

New to coding and trying to jump right in!
I have a new list of customers I'm responsible for in a spreadsheet, and I receive an email from someone I don't immediately recognize.
I need to set up a script to:
1. determine if they are in my book of business
2. if they are in my book of business, send a template email regarding next steps (email A)
3. if they are not in my book of business, send a template email that i'm not their POC and redirecting them to relevant resources (email B)
I believe I need to set up a loop (if/else?) to see if the email I received is from a sender on the list, if it is, send email a, if it isn't send email b.
Does anyone have feedback on my stab below? I've set up a dumbie example I will constantly be working on and updating. https://docs.google.com/spreadsheets/d/1HcLluPhRgl0ihQT0GA-ZFj1KsOPHxl0dU08EFlh2Gss/edit#gid=0
For the if/else I believe I would start with
if (CustomerName) {exists Send email A
} else {Send Email B
}
// The code below will send an email with the current date and time.
var now = new Date();
GmailApp.sendEmail("jlennon#gmail.com", "current time", "The time is: " + now.toString());

How do I send an E-mail to a discussion group in OpenERP 7?

I've created a new discussion group in OpenERP 7 under messaging. I'm trying to send a notification email to all the members of the group when the status of a task is changed. I have already tried creating an automated action and linking to server action of type email. But, in server actions, how to address the particular group? The group name is supervisors.
Is there a way to trigger a mail, when a particular function is called?
I had to tackle the same, here is a snippet that I wrote:
def cron_notification(self, cr, uid, context=None):
mail_group_obj = self.pool.get('mail.group')
mail_group = mail_group_obj.browse(cr, uid, 4, context=context)
body = 'sexy body'
mail_group.message_post(body=body, subject=False, type='comment', context={
'default_model': 'mail.group',
'default_res_id': 4,
'mail_post_autofollow': True,
'mail_post_autofollow_partner_ids': [],
}, content_subtype='plaintext',
partner_ids=[],
attachment_ids=[],
subtype='mail.mt_comment'
)
return
This code will send a message "sexy body" to group with id=4. Whoever should receive this message will have to follow this mail.group and set in his "preference" section to receive all Emails.
(This code should work as it is for any object similar to 'mail.group' that inherits mail.thread)
I dont know which of all those parameters are redundant as I stopped once it worked and never "optimized" it. Feel free to use this snippet wherever you want.

how to send files as attachment in email in magento for downloadable products?

I am new to Magento. I am working on a web site which is selling downloadable products.
My client want purchased products should be sent via email in attachment?
Currently, I am developing in localhost so I am not sure whether magneto actually send product files in email or not?
Should I need to enable any option for that in configuration?
If you want to develop this at your localhost keep in mind, that you have to set up mail server or use some solutions from community like below link, to send it by gmail and other:
https://www.magentocommerce.com/magento-connect/smtp-pro-email-free-custom-smtp-email.html
You also can just configure your server to save mails without sending.
So you'll be able to review it.
Good article about how to send downloadable by email here:
https://magento.stackexchange.com/questions/49511/how-can-i-get-only-the-downloadable-product-url-in-email-template
But!!! keep in mind that the latest Magento use queue to send email (which runs by cron), so if you have such a distribution (for example 1.9+) you need to adjust code which you have from link above.
Here istwo solutions for this case:
Disable adding email to queue after order.
Just comment this part of code in "Mage_Core_Model_Email_Template"'s "send()" method:
// if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {
/** #var $emailQueue Mage_Core_Model_Email_Queue */
/* $emailQueue = $this->getQueue();
$emailQueue->clearRecipients();
$emailQueue->setMessageBody($text);
$emailQueue->setMessageParameters(array(
'subject' => $subject,
'return_path_email' => $returnPathEmail,
'is_plain' => $this->isPlain(),
'from_email' => $this->getSenderEmail(),
'from_name' => $this->getSenderName(),
'reply_to' => $this->getMail()->getReplyTo(),
'return_to' => $this->getMail()->getReturnPath(),
))
->addRecipients($emails, $names, Mage_Core_Model_Email_Queue::EMAIL_TYPE_TO)
->addRecipients($this->_bccEmails, array(), Mage_Core_Model_Email_Queue::EMAIL_TYPE_BCC);
$emailQueue->addMessageToQueue();
return true;
}*/
So emails will be sent immediately (be aware, that if you have very big turnover with spikes it can create performance issue)
Second way is to save full path of attachment to table "core_email_queue" field - "message_parameters". You can do it adding url to array of argument here $emailQueue->setMessageParameters( in code above.
After that you can handle it in "Mage_Core_Model_Email_Queue"'s "send()" method
using standard "Zend Mail"'s method - "createAttachment()". Below link provides deeper explanation of this part.
https://magento.stackexchange.com/questions/9652/magento-send-file-attachements-in-emails
Hope it will help sombody.
Have a good day!!!

Drupal link append re-direct url

I am using the following code to create a link to the create user page:
l('create new user', 'admin/people/create');
It works perfectly but is there a way to include a destination with the function so when the submit button is clicked it returns my user to the page of origin?
I am attempting to accomplish it with the following code:
$link = l('create new user',
'admin/people/create&destination=group/node/5/admin/people/add-user');
but when I click my link get sent to admin/people which means the first part of the process has already failed
This should do it:
l('create new user', 'admin/people/create', array('query' => array('destination' => 'group/node/5/admin/people/add-user')))