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.
Related
Can anyone help with some tips on how to queue email using an OctoberCMS ajax page?
function sendRecipientMsg($dataset, $sendCounter, $recipients){
$template = $dataset['template'];
Mail::queue($template, $dataset, function($message) use($dataset, $recipients){
$message->to('piggy#teamprema.co.nz','MissPiggy');
$message->subject('Have a good day');
$message->from('us#prema.co.nz', 'Mike and Stephie');
$message->sender('us#prema.co.nz', 'Mike and Stephie');
trace_log('$message');
$message->cc($address, $name = null);
$message->bcc('systems#safe.org.nz', 'SAFE Campaigns Feedlots ECards');
});
}
This code works when we use Mail::send but not with Mail::queue
Any help or tips very welcome
In your config/queue.php file, which driver do you have set as the default?
For example: 'default' => env('QUEUE_DRIVER', 'sync')
(if you are using DotEnv then check the .env file in your docroot).
If you are using sync, it should send right away as sync is really only for development and will still block.
If you are using another method, like database, then you do have to ensure that your queues are configured to process how you expect.
Try running php artisan queue:work, then trigger your ajax call and it should send.
this question is related to HTML image not showing in Gmail , but the answers there do not (or no longer) work.
the problem is that my perl program (below) fails when my html-formatted messages that I want to send off as soon as an img tag is included. it does not matter whether the image itself is served from the google drive or not. I am guessing that I am running into a novel gmail restriction (my script used to work), but I am not sure.
(of course, this problem is not that my recipients do not see the image; it is that the sending perl script aborts with an error---unfortunately, not with more information explaining to me why it is an error. of course, I understand that my recipients need to agree to view images to prevent tracking.)
so here are my questions:
is this a gmail or a perl module problem?
is it possible to send images, so that if my recipients want to see
images from my website (preferably not just images from my google drive as in my example below), they can agree to see this?
is it possible to get a better error message from google about why it fails?
here is the [almost] working code:
#!/usr/bin/perl -w
use strict;
use warnings;
use Email::MIME::CreateHTML;
use Email::Send;
use Email::Send::Gmail;
my $toemail = 'ivo.welch#gmail.com';
my $subject = 'testing image mailing';
my $bodytext= '<html> <body> fails: <img src="https://drive.google.com/open?id=1K4psrWWolTSqx_f6MQP-T1-FMFpegT1Trg" alt="photo" /> </body> </html>\n';
use readcredentials;
my $gmailaccount= readcredentials( 'account' );
my $gmailuserlogin= readcredentials( 'userlogin');
my $gmailpasswd= readcredentials( 'gmailpassword');
eval {
my $message = Email::MIME->create_html(
header => [
From => $gmailaccount,
To => $toemail,
Subject => $subject,
],
body => $bodytext,
);
my $sender = Email::Send->new(
{ mailer => 'Gmail',
mailer_args => [
username => $gmailuserlogin,
password => $gmailpasswd,
]
}
);
$sender->send($message);
};
warn "Error sending email: $#" if $#;
print STDERR "emailed!\n";
I ran your script, with some modifications to remove the dependency on readcredentials to make it run in my environment, and the email was delivered with no problem. Problems could be:
You could have some problems with your gmail credentials.
The script downloads and attaches the image, so perhaps your local environment is preventing the image from being downloaded.
But without your specific error message, it's hard to diagnose any further.
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());
});
I have following questions. Assuming I have following code
public class MessageMaker {
public static void helloMessage() {
System.debug( 'Entry point' );
Case c = new Case();
insert c;
EmailMessage e = new EmailMessage();
System.debug( 'EmailMessage created' );
e.parentid = c.id;
// Set to draft status.
// This status is required
// for sendEmailMessage().
e.Status = '5';
e.TextBody =
'Sample email message.';
e.Subject = 'Apex sample';
e.ToAddress = 'my#mail.com';
insert e;
List<Messaging.SendEmailResult>
results =
Messaging.sendEmailMessage(new ID[]
{ e.id });
System.debug(results.size());
System.debug(results[0].success);
System.debug(results[0].getErrors().size());
System.assertEquals(1, results.size());
System.assertEquals(true, results[0].success);
}
}
1.First question. I want to find out using apex code if the message was really delivered.
Here documentation says http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_sendemail_emailresult.htm
Even if success = true, it does not mean the intended recipients received the email, as it could have bounced or been blocked by a spam blocker. Also, even if the email is successfully accepted for delivery by the message transfer agent, there can still be errors in the error array related to individual addresses within the email.
So I have been trying to send email by apex code and look for results[0].success. It seems it says like it is described in documentation, so success is true even though email address was incorrect.
Also I have tried to check this manually through email logs http://eu2.salesforce.com/help/doc/en/email_logs.htm
And I have found following row in resulting log regarding my email sent to incorrect address
9/2/2013 9:36 66/FC-09306-20B54225 T julfy#i.ia
julfy=i.ua__0-6uvic1ltvun1nf#95mngihd2hpe0w.b-ysubea0.bl.bnc.salesforce.com 1434 005b0000000J7bm
<_0vTJ000000000000000000000000000000000000000000000MSHRSY00W1-CKg3DShWC5xu24ccHFA#sfdc.net>
1 311.627583 421 4.4.0 [internal] no MXs for this domain could be
reached at this time
But I don't know how to access this information by apex code. Any thoughts?
Second question. If message was delivered and recipient forwarded it, is any possibility to monitor that using apex code? Anybody?
You can't do either of those things. APEX runs on Salesforce's servers and when you send an email it leaves that environment. The only time you can monitor a successful response is when you're dealing with an API that generates webhooks.
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!!!