Envoi d'un mail sans attendre la chargement

Messages postés
1
Date d'inscription
samedi 1 septembre 2018
Statut
Membre
Dernière intervention
1 septembre 2018
-
Bonjour,
QUAND JE CLIQUE SUR LE BOUTON ENVOYER (MAIL) Je dois pas quitter la page d'envoi depuis 3 menuises pour recevoir un mail.
mais je besoins de naviguer sur mon site (quitter la page d'envoi) et recevoir un mail quand même.
et pour cela je utiliser un thread
et voici mon code et je ajouter un thread :

protected void SendRejectionsToFiliales()
{
RejectManagmentHelper rejectHelper = new RejectManagmentHelper(this._sSqlConnectionString);
PARAM_AFFILIATE_DAO affiliateDao = new PARAM_AFFILIATE_DAO(this._sSqlConnectionString);

HiddenField1.Value = "";

List<ExcelPackage> exelFiles = rejectHelper.CreateLogOfRejectFilesByCompany(HiddenFiledSendRejectMailsLoopCondition.Value);

ServicePointManager.ServerCertificateValidationCallback =delegate (object s, X509Certificate certificate,X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
CONFIGURATION_DAO configDao = new CONFIGURATION_DAO(this._sSqlConnectionString);
CONFIGURATION config = configDao.Get("reject_mail_adress");
string sSender = config.value;
config = configDao.Get("reject_mail_title");
string sSubject = config.value;
config = configDao.Get("reject_mail_content");
string sMsgText = config.value;
config = configDao.Get("reject_mail_smtp_host");
string sSMTPHost = config.value;
config = configDao.Get("reject_mail_port");
string sSMTPPort = config.value;
config = configDao.Get("reject_mail_password");
string sSenderPassword = config.value;

foreach (ExcelPackage exelFile in exelFiles)
{
FileInfo fo = exelFile.File;
string sCompanyCode = fo.Name.Substring(4, 3);

PARAM_AFFILIATE affiliate = affiliateDao.GetByCompanyCode(sCompanyCode);
string sMailTo = affiliate.affiliateEmailOfReject;
//HiddenFiledSendRejectMailsLoopCondition.Value = sCompanyCode;
MailMessage objMailMsg = new MailMessage(sSender, sMailTo);
objMailMsg.BodyEncoding = Encoding.UTF8;
objMailMsg.Subject = sSubject;
objMailMsg.Body = sMsgText;
objMailMsg.Priority = MailPriority.High;
objMailMsg.IsBodyHtml = true;
Attachment at = new Attachment(new MemoryStream(exelFile.GetAsByteArray()), fo.FullName);
objMailMsg.Attachments.Add(at);

//prepare to send mail via SMTP transport
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = sSMTPHost;
System.Net.NetworkCredential basicauthenticationinfo = new System.Net.NetworkCredential(sSender, sSenderPassword);
client.Port = int.Parse(sSMTPPort);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = basicauthenticationinfo;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
Thread email = new Thread(delegate ()
{
client.Send(objMailMsg);

});

email.IsBackground = true;
email.Start();
}
catch (Exception ex)
{

}
}

HiddenFiledSendRejectMailsLoopCondition.Value = "0";
}
Afficher la suite