c# - Doubts on sending more than one email asynchronously in MVC3 -
In my application, I have a functionality to save and publish articles. So when I click on the "Save and Publish" button, there are three things:
- Published articles are saved in the database.
- A notification email leads to a group of users new articles are available.
- After sending the email page, redirect to the "Articles List" page, do not show any success or failure message for the email.
Now the number of users who receive emails can vary, such as 10, 30 50 and so on. I want to send the notification email asynchronously, so that until all the mails are received from the receptionist, that page will not be blocked, the code below is a piece of code from the "PublishArticle" action method
foreach (string in email id) {ArticleNotificationDelegate proc = Email.Send; IAsyncResult asyncResult = proc.BeginInvoke (subject, body, from, to, cc, null, null, void); }
Below I have defined a representative to use the
send method
personal representative bool ArticleNotificationDelegate (string Subject, string body, string to, string from string cc, string bcc = null);
And this is the code to send email:
Send Public Stable Bull (string subject, string body, string to string, string Cc, string bcc = null) {bool reaction; Mail message mail = new mail form (); Address from mail address = new mail address (to); (To) mail.To.Add; If (! String.Insnall of WatchSpace (CC)) {mail.CC.Add (CC); } If (! String. Isolated whitespace (BCC)) {mail.BC.Add (bcc); } Mail.from = fromAddress; similarity. Subject = topic; similarity. Body = body; mail.IsBodyHtml = True; similarity. Priority = mail priority. High; SmtpClient Client = New SmtpClient (); Try {client.end (mail); Reaction = true; } Hold (exception) {response = false; } Finally {client.Dispose (); Mail.Dispose (); } Return response; }
Although this code is working fine but still I want to know that this is my viewpoint and will not have any problems in the future.
If there is a better way to fulfill my purpose, please suggest meNote: As I am using the .NET Framework 4.0, therefore available in
Asin and
waiting 4.5 is.
Besides, I used theclient.SendAsync by changing
client.Send and above all my code
send the same method was . No change was being sent after this change and it was also not an exception. So I did not go with this change
I want to send the notification email asynchronously so that the page block will not be available Not all mails go to their receptionist.
This is a very dangerous method, because ASP.Net will feel free to empty your app domain if there is no active request. ASP.NET Do not know that you have worked in line for your thread pool (via
BeginInvoke ). I suggest that you want to send trustworthy email.
Comments
Post a Comment