Reputation: 823
I have already looked into these question :
How do I set up mailto for bcc only
how to open outlook on click of email hyperlink
but they don't answer my problem because what im trying to do is open the default email client (normally outlook but could be gmail too so it has to work with both) with a list of destinations and all of them should be put as Bcc. I can't put them 1 by 1 since the list changes continuously
Note : this project is made in asp.net mvc 5 and the model contains the list of destination I want to send to and has a field called Email ( I put only the relevant code of the page) and spamming won't be a problem since only admin can use this link.( I know Mailto can be abused sometimes by spammer)
Here is an example of what I tried but I just can't figure out how to format the string properly before putting it in the tag. So if there is a better way than this I don't mind modifying the logic.
@model List<Inscription>
string Destinations= "mailto:?bcc=";
foreach (var Inscription in Model.ToList())
{
Destinations = Destinations + Inscription.Email + ",";
}
<a class="btn btn-default" href="@Destinations">Send Email to all</a>
it just dosen't see them all in outlook and those that I didn't see got no email ( I tested Multiple time)
Im pretty sure its just an error of formatting or something like that on my part but I just can't see it
Upvotes: 2
Views: 1266
Reputation: 823
As said by @James Thorpe outlook need a ";" to separate the emails while gmail needs "," so instead of just having a simple button its gonna open a modal which will ask the client if they are using outlook or gmail
Here is I would do it :
@model List<Inscription>
string DestinationsGmail= "mailto:?bcc=";
string DestinationsOutlook= "mailto:?bcc=";
foreach (var Inscription in Model.ToList())
{
DestinationsGmail = DestinationsGmail + Inscription.Email + ",";
DestinationsGmail = DestinationsOutlook + Inscription.Email + ";";
}
<a id="OpenModel" class="btn btn-default" data-target="#basicmodal" data-toggle="modal">Choice of Email Sender</a>
<div class="modal fade" id="basicmodal" tabindex="-1" role="dialog" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">Which client to use</h4>
</div>
<div class="modal-body">
the links are going to open your default Email Client so choose the one you have :
<a class="btn btn-default" href="@DestinationsGmail">Send Email to all with gmail</a>
<a class="btn btn-default" href="@DestinationsOutlook">Send Email to all with outlook</a>
</div>
<div class="modal-footer">
</div>
</div>
</div>
Upvotes: 1