c# - Schedule email at specific time with different timezone -


optimized way send daily digest email user @ time of 11.30am according time zone,

sending email user working fine send @ specific time timezone?

what have

userprofile timezoneid,emailid dynamic daily email content 

currently doing console application send @ 11.30am @ utc time,

but how handle in multiple timezone?can me out?

i have achieved type of functionality via console application running scheduled task polls database every x minutes see if emails need sent.

i assuming userprofile database table holding user list.

to achieve add additional column table store last sent date/time. necessary when start sending timezone cannot send emails @ same time each day , need track ones have been sent or ones need sent.

also due nature of type of task if reason fails or isn't running reason may need "catch-up" i.e. send missed emails (although may not requirement you) can achieved checking last sent column.

assuming want send email @ (or close to) 11:30am local time each user following code should work:

ilist<userprofile> users = // load user profile database  foreach(userprofile user in user){      // work out users local time converting utc local timezone     datetime localdatetime = timezoneinfo.converttimefromutc(datetime.utcnow, user.timezoneid);      if(user.lastsent.hasvalue && user.lastsent.value.date == localdatetime.date){        // sent email today        continue;     }      if(localdatetime.hour >= 11 && localdatetime.minute >= 30){        // after 11:30am send email (this later 11:30 depending on other factors)        if(sendemail(user.emailid)){            // update last sent must in local time            user.lastsent = converter.tolocaltime(datetime.utcnow, user.timezoneid);             // save user entity            // userpersistence.save(user);        }      }  } 

now caveat code above send email 11:30 has been reached provided code running , dependent on volume of users/latency of sending each email etc. if have scheduled task running every 5 minutes accuracy going to nearest 5 minutes may not send until 11:35am. run scheduled task more if want more accuracy. consideration if have 30000 users in same time zone latency of sending volume of emails naturally mean not can sent @ 11:30am.

that said code above should started in right direction.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -