passing data to mailgun webhooks in laravel - email

Im using laravel and configured mailgun to send mails
I want to use webhooks to track them.
so I need to send data with the message so I can track it using the web hook
for example attach a message id to each mail I send
tried to follow the mailgun documnation but no luck
this is my code for sending the mail
$data = array('course_name' => $course_name,'grade' => $grade,'email' => $stud->email,
"v:messageId" => "123");
Mail::send('emails.stud_feedback',$data, function ($message) {
$message->to($this->email)->subject( $this->course);
$message->attach($this->file, ['as' => 'feedback']);
});
according to the documnation the web hook should post me the message id,
but Im not getting it.
what am I doing wrong?

solved by setting headers to the mail:
$message->getHeaders()->addTextHeader('X-Mailgun-Variables', "{'messageid:123}'}");

Use This :
Mail::send('emails.test',[]), function ($message) use ($subject, $from, $emails) {
dd($message->getSwiftMessage()->getId());
});

Related

ccing using SendGrid Service in Bluemix

Trying to use SendGrid Service in Bluemix coding in Node.js. I use the addCc() method to add an address to cc to. I get no error msg and the mail is delivered to the main address, but nothing gets sent to the cc:ed address. And if I look ath the top of the mail going to the main recipient I can see the cc address there. Does anyone know if there is a bug or limitation in using cc with SendGrid?
Best Regards
W
A common error is to pass an array to the addCc() function when it expects a string. Using v2.0.0 of the 'sendgrid' npm module, the code below will correctly send an email which cc's 'jennifer#electric.co'.
As mentioned in the comment above, verify that you're not hitting issue https://github.com/sendgrid/sendgrid-nodejs/issues/162
// Pre-req: get the SendGrid credentials for username and password
// from VCAP_SERVICES into the 'user' and 'pass' vars
var sendgrid = require('sendgrid')(user, pass);
var email = new sendgrid.Email({
to: 'fargo.north#electric.co',
from: 'bronco.bruce#electric.co',
subject: 'SendGrid Test',
text: 'This is a SendGrid test'
};
// add a cc address as a single string
email.addCc('jennifer#electric.co');
sendgrid.send(email, function(err, json) {
if (err) {
return console.error(err);
}
console.log(json);
}

Sending and Queuing emails in laravel

Hello i am trying to send emails in laravel this is currently what i do:
$parameters = array(
'date_of_purchase' => date('l, d m Y H:i A'),
'amount' => $amount,
);
// Sending Mail
Mail::queue('emails.bus-ticket-purchase', $parameters, function ($message) use ($customer_email) {
if ($message->to($customer_email, '')->subject('Ticket Purchase')) {
$all_good = true;
}
});
This works fine,all emails get delivered, but i started getting complaints about how some emails were taking about an hour to come through so i decided to read laravels documentation on emails and queues, what i found there was actually quite different from what i had done:
Laravel Mail Queues
So i run the artisan command to create the SendMail command and tried to folow the rest of the documentation but i still do not get it, it states that to send a mail(push it on a queue) i should do this:
Queue::push(new SendEmail($message));
Now where does the above code go? In my SendMail command or in my controller? Is there somewhere where i can see how this all works, i would really like someone to explain all this to me.

Cakephp : add more recipients before send an email

I have to send an email to several recipients, but only if my current email address is marked as 'out of office'. In order to do that I will need to check the condition before sending the email and to retrieve my backups and add them in $to .
I currently managed to find a quick fix, I've modified CakeEmail, but it seems a little wrong to alter this file.
Any ideea of how I can do this without modifying CakeEmail?
Thank you,
In your configuration (core.php) file you create a new configuration
Configure:write( 'notify_people', array( 'email1#example.com' => 'Email1', 'email2#example.com' => 'Email2' );
Then you use the CakeEmail::to() to add recipients before sending an email. So you update all your $email->to() calls to read the configuration value instead.
$email = new CakeEmail();
$email->to( Configure::read( 'notify_people' ) );
//TODO: configure sender, subject etc...
//finally send the email
$email->send( $bodyOfTheMessage );
When you need to change the list of recipients you only have to do it once in the configuration file.

Sending email from Magento to fails

I am trying to send an email from a custom module in magento, however it fails to send it.
do i need to include anything or should i make some configuration with my hosting?
Here you can see my code:
$mail = new Zend_Mail();
$mail->setBodyText($mailbody);
$mail->setFrom('admin#gmail.com', 'admin');
$mail->addTo('email#gmail.com', 'client');
$mail->setSubject('Error report');
try {
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
}
catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to send.');
}
It's better to use Magento's models for sending email. This way you know it's being send correctly, and get userful errors when it fails
The most simply way:
$email = Mage::getModel('core/email_template');
$email->setSenderEmail('sender#email.com');
$email->setSenderName('name');
$email->setTemplateSubject('Subject');
$email->setTemplateText('emailbody');
$email->send('receiver#mail.com', 'receiver name');
Remember that you host my not support sending mail, or that your provider is blocking port 25. This will result in a message in your exception.log
If you want to see how the final email looks, print $email->getProcessedTemplate() onto your screen
You have to configure your smtp in php.ini
What is your provider ? It's possible to find the smtp server's url, and put it in your php.ini file.

Is it possible to send an e-mail programmatically in Magento?

Is it possible to send an e-mail programmatically in Magento? Maybe from a controller in a custom module, could you get hold of a template, populate its variables, and send the e-mail?
Thanks.
Absolutely. Here's an example from the Checkout helper:
$mailTemplate = Mage::getModel('core/email_template');
$template = Mage::getStoreConfig('checkout/payment_failed/template', $checkout->getStoreId());
$mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$checkout->getStoreId()))
->sendTransactional(
$template,
Mage::getStoreConfig('checkout/payment_failed/identity', $checkout->getStoreId()),
$recipient['email'],
$recipient['name'],
array(
'reason' => $message,
...
'total' => $total
)
);
It's certainly possible. The email handling in Magento is quite powerful (and can be complex).
Without knowing exactly what you're trying to achieve, it would be worth you starting off by looking at the Mage_Core_Model_Email_Template class as that drives Magento's email handling.