Laravel Mail accessing object in mail view when sending to bulk recipients? - laravel

As the title says I am trying to access recipient when sending bulk mail.
Right now I am doing this, sending to participants collection with info about event, but I also want to access each participant in view.
Mail::to($this->participants)->send(new News($this->event));
I could do a foreach but I do not think that is efficient.
I need something like this, so I could get the participant in the mail class to send it to view.
Mail::to($this->participants)->send(new News($this->event, $this->participant));

Related

How to send message to several specific users Laravel Notification?

I studied the Laraval.s notifications. I can not realize how to send bulk notifications to the specific users. I know their ids.
Should I use private channel or broadcast?
in laravel there are two way to send notificatons
$user=User::find(1) ;
$users=User::all() ;
$user->notify(new InvoicePaid($invoice))
// or
Notification::send($users,new InvoicePaid($invoice))
so both ways send only one notification but we can send it to single or multiple users.
if you need to send multiple notifications to multiple users you should use loops:
$notifications=[new InvoicePaid($invoice) ]
foreach($notifications as $notification)
{
Notification::send($users,$notification)
}
also there is a better way to handle this.you can use event and it is better to use event to send notification or perform other task after a specific action. for example define a event as userRegisterd. then you can assign one or more listener to this event like sendNewUserNotification , congratulationsNotification.
in each listener notify the users

Best way to achieve Conversation view for mail folder using Outlook REST API

I would like to use the Outlook REST API to display the messages in a mail folder and group messages by conversations, like you have in any modern webmail.
For example with inbox, I would request using a first query such as <mailuri>/inbox/messages?$select=ConversationId (by default it is reverse chronological order)
It is not sufficient to group this request results by ConversationId because some emails may not be in inbox (think of sentmails) or they may be paginated and not returned in the first page.
Consequently, for each distinct ConversationId I need to perform another REST request, for retrieving participants or simply counting the emails in the conversation. I may use the new batch request to do this.
There are a lot of requests involved. Is there a better solution ?
As you've probably realized the REST API doesn't directly provide a way to work with conversations as an entity. This is something that we have on our roadmap to improve.
With the current state of the API what you're describing is basically the right approach. You could possibly defer the second request to "fill in" a conversation until the user selects it.
You can actually use this endpoint to cover both inbox and sentitems
https://outlook.office.com/api/v2.0/me/messages/?$select=ConversationId & $filter=ConversationId eq '${params.conversationId}'

Google apps - Trigger script when responseStatus change

I would like to run a script each time the responStatus of an event is modified by an attendee.
By default when an attendee receive an invitation by email the status is "needsAction". And wether he accepts, decline, the responseStatus change to "accepted" or "declined".
I want to create a script which send a custom email, and trigger each time the status is changed by the attendees.
Anyone ?
Here is a simple tutorial on sending emails from a spreadsheet. Note that you will need to add a column to denote that the email was sent as it will go through every row and send the spreadsheet.
I prefer this example as a more complete one which does a mail merge as well, allowing you to have a template message and replacing it with values from the row.
Go through this and as you have more specific questions, start a new thread.

How to get message_id of emails sent using transmission?

We're moving from Mandrill to SparkPost. We figured that SparkPost's transmission is the closest thing to Mandrill's send-template message call.
Mandrill responded to those calls with a list of ids and statuses for each email. On the other hand SparkPost returns a single id and summary statistics (number of emails that were sent and number of emails that failed). Is there some way to get those ids and statuses out of the transmission response or at all?
you can get the message IDs for messages sent using the tranmissions API two ways:
Query the message events API, which allows you to filter by recipients, template IDs, campaign IDs, and other values
Use webhooks - messages are sent to your endpoint in batches, and each object in the batch contains the message ID
Which method you choose really depends on your use case. It's essentially poll (message events) vs. push (webhooks). There is no way to get the IDs when you send the transmission because they are sent asynchronously.
Querying message events API, while a viable option, would needlessly complicate our simple solution. On the other hand we very much want to use Webhooks, but not knowing which message they relate to would be troublesome...
The missing link was putting our own id in rcpt_meta. Most of the webhooks we care about do contain rcpt_meta, so we can substitute message_id with that.
I'm stacked too in this problem..
using rcpt_meta solution would be perfect if substitution would work on rcpt_meta but it's not the case.
So, in case of sending a campaign, I cannot specify all recipients inline but have to make a single API call for every message, wich is bad for - say - 10/100k recipients!
But now, all transmission_id are unique for every SINGLE recipient, so I have the missing key and rcpt_meta is not needed anymore.
so the key to be used when receiving a webhook is composed:
transmission_id **AND** rcpt_to

Rails private messages how to create a conversation view?

I am using this gem for private messages: https://github.com/jongilbraith/simple-private-messages
I want to create a thread conversation instead of the e-mail conversation the scaffold have provided.
Example, User A have sent 10 messages to User B. User A have also sent 10 messages to User C.
Instead of looping through all the messages. (e-mail look) I want to create a threat like:
Inbox
Conversation with User A (10 messages)
Conversation with User C (10 messages)
And when clicking on the conversation the messages should be ordered after date. So it would be like a conversation.
The table for messages:
id
sender_id
recipient_id
sender_deleted
recipient_deleted
subject
body
read_at
created_at
updated_at
How do I create these views? How do I group the messages?
Short answer is: you can't with that gem. You'll have to extend it and add a Conversation model then bridge that between users and messages.
I propose, instead, you use this gem:
https://github.com/ging/mailboxer
Far more powerful than your current gem, and it comes with conversations out of the box. I've used it before to mimic a gmail-like view.
From the guide:
#alfa wants to retrieve all his conversations
alfa.mailbox.conversations
#A wants to retrieve his inbox
alfa.mailbox.inbox
#A wants to retrieve his sent conversations
alfa.mailbox.sentbox
#alfa wants to retrieve his trashed conversations
alfa.mailbox.trash
Easy as pie:
current_user.mailbox.conversations.each do |convo|
convo.subject
...
end

Resources