I create a simple mailer for our updates into client emails, But how can I send the data one by one and process each data on server side
html:
<p class="response"></p>
<form id="send_updates">
{% csrf_token %}
<textarea name="mail-list" class="mails" id="mails"></textarea>
<button type="submit"> start sends </button>
</form>
javascript:
let mails = $('#mails').val().split('\n');
for(let i = 0; i <= cc.length; i++){
$.ajax({
cache: false,
type: 'post',
url: "{% url 'send_mail' %}",
data: {'email': mails[i]},
async: true,
beforeSend:function(xhr, settings){
xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
};
success: function(data){
if (data.success) == true{
$('.response').append(mails[i] + ' sent!')
}else{
$('.response').append(mails[i] + ' not sent!')
};
}
});
BUT! It Sends All Request without waiting if it Success or Not
EDIT:
We Want to Monitor One By One If That Email is Send Successfully or Not!