473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

send mails asynchronously in wcf

1
Hello,

I am doing a wcf C#.net project in which i need to send multiple emails asynchronously with one pdf attachment. I use smtp.sendAsync() to do it. Please guide me on this and clarify my doubts.


The logic i have used is, store all the receiver's email ids in a list. Then, in a foreach loop, inside each loop call my function say, sendMailsaAsynch(objList, filename). This function is responsible for opening the pdf file using the filename specified, and attach it to a new object of MailAddress and call smtp.sendAsync().

Expand|Select|Wrap|Line Numbers
  1. function sendMailsAsynch(objList, filename)
  2. {
  3. //open the file
  4. fs = new FileStream(...)           //LINE 1
  5. mm = new MailMessage();
  6. Attachment a = ....
  7. .. smtp = new 
  8. try
  9. {
  10.  smtp.SendCompleted += new SendCompletedEventHandler(smtp_OnCompleted);
  11.  smtp.sendAsynch();
  12. }
  13. catch{ throw;}
  14. finally { }
  15.  
  16. }
I want to delete the file in the finally. but i cannot access the file. Because, it says file is used by w3wp.exe. If i use mm.Dispose() in finally, none of the emails is sent. You may ask why i open the same file in every each loop in the LINE 1. But IF i do it in the calling function as shown below in the commented line, none of the emails are sent. I get Failure sending mail. some error like: Cannot access the mailaddress object. (Please explain where i can delete the file and how to delete it. I created the file using fs = new FileStream(filename, FileMode.Open, FileAccess.Read))


The following is how i call the function in foreach loop.

Expand|Select|Wrap|Line Numbers
  1. funcion sendMails(List list)
  2. {
  3.    //fs = new FileStream(....)
  4.    foreach(List l in list)
  5.    {
  6.       sendMailsAsynch(list, filenme);
  7.    }
  8. }

One more important thing is: If i keep breakpoint and check in the smtp_OnCompleted delegate function, sometimes the breakpoint is hit after all the try-catch-finally is completed. ie. after all the loops are finished. But sometimes i get the breakpoint hit on this delegate function after the end of each try-cath ie. at the end for each loop. Can anyone explain how threading is handled here.

I do not want to use MessageQueing. I think it is not much of a complex issue. Hope someone will surely solve this. Thanks in advance.
Oct 15 '12 #1
0 1628

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: tomtailor | last post by:
Hello! I'm migrating from pgSQL and WinXP to DB2 8.2 on SuSE 9.2 and I'd like to send E-Mails by triggers. I found some code for Java stored Procedures but I'm not able to get JavaDK running in...
1
by: Duy Nguyen | last post by:
how can I send mails from asp.net pages?
1
by: SenthilVel | last post by:
Hi all Does the namespace Sysytem.Web.mail use CDO's to send mails? ,,, Senthil
1
by: Anuradha | last post by:
Dear All I tried below method to send mails but when the mail sends it gives an error saying Dim mail As MailMessage = New MailMessage() mail.To = "anu@lanka.com" mail.From =...
0
by: Parul | last post by:
How could we send mails automatically using ASP.Net. I have to make a remainder of shows by which I can send notifications of remainder to the users before there shows starts.
0
iamnandagopal
by: iamnandagopal | last post by:
Hello Guys, I would like to know how to send mails programatically using C#. My mail server is an Microsoft Exchange. I dont have much idea about Microsoft Exchange. I would really appreciate...
10
by: muskan | last post by:
Hello, I have written this code for sending mails but is not working. Tell what should I have to write after the equal sign in SmtpMail.SmtpServer = ; so mail to be stored in...
7
by: oopsbabies | last post by:
Hello everyone, I am using Apache 1.3.33 as the web server and PHP version 4.3.10. My machine is using Windows XP 2002 professional edition which comes with a Windows firewall. I am using McAfee...
1
by: mukesh1989 | last post by:
using CDOSYS i am able to send mails only to Gmail but not to the other mails why? and also in Gmail mail it will be in Spam folder if i say it is not spam also! please help me. sometimes it takes...
1
by: swetha123 | last post by:
hello, can any tell me how to send mails from site using mail() in php do we need to change in the php.ini these are in php.ini
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.