Last post Oct 28, 2016 10:55 AM by gfw
Oct 23, 2016 08:32 PM|av2020|LINK
i would like to send out following query to all email users daily basis,can anyone guide me the direction,
its incorporated the same in ASP.NET also. would appreciate if you can guide if that from ASP.NET webform.
SELECT * ,[action_id],DBO.UtcToLocal(creation_date) as Creation_Date,[event_name]
,[person_num] FROM [dbo].[TEST] WHERE preffered_name = 'finance' AND dbo.UtcToLocal(creation_date) >getdate()-50 AND dbo.UtcToLocal(creation_date)>dateadd(dd,-52,convert(date,getdate()))
Oct 24, 2016 09:54 AM|Yohann Lu|LINK
Do you want to send the query string or query result? I think you could try to use HttpRuntime.Cache.Insert or Timer. Here is a simple code for HttpRuntime.Cache.Insert.
public class WebApiApplication : System.Web.HttpApplication
private static CacheItemRemovedCallback OnCacheRemove = null;
protected void Application_Start()
private void AddTask(string name, int seconds)
OnCacheRemove = new CacheItemRemovedCallback(CacheItemRemoved);
HttpRuntime.Cache.Insert(name, seconds, null,
public void CacheItemRemoved(string k, object v, CacheItemRemovedReason r)
// do stuff here if it matches our taskname, like WebRequest
// re-add our task so it recurs
private void SendEmail()
SmtpClient client = new SmtpClient("smtp.office365.com", 587);
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("your sender mail account", "password");
MailAddress from = new MailAddress("your sender mail account", String.Empty, System.Text.Encoding.UTF8);
MailAddress to = new MailAddress("receiver account");
MailMessage message = new MailMessage(from, to);
message.Body = "The message I want to send.";
For timer, I suggest you refer the link below:
# Run a piece of code once a day automatically in asp MVC
Oct 26, 2016 04:58 PM|av2020|LINK
Below code is by clicking the button the email attachment is going to respective email account and same this i need by auto-function.should be send out everyday with specific time , from gridview @ sql results. below is working code manual button click
protected void Button2_Click2(object sender, EventArgs e)
public void fn_AttachGrid()
StringWriter stw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(stw);
MailMessage mail = new MailMessage();
mail.IsBodyHtml = true;
mail.Subject = "Time Report";
System.Text.Encoding Enc = System.Text.Encoding.ASCII;
byte mBArray = Enc.GetBytes(stw.ToString());
System.IO.MemoryStream mAtt = new System.IO.MemoryStream(mBArray, false);
mail.Attachments.Add(new Attachment(mAtt, "r.xls"));
mail.Body = "Dear Team Find Attached Time Ae sheet details";
SmtpClient smtp = new SmtpClient();
mail.From = new MailAddress("email.gmail.com", "rfr");
smtp.Host = "smtp.gmail.com";
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(@"email.gmail.com", "password");
smtp.EnableSsl = true;
smtp.Port = 587;
Label3.Text = "Email Sent";
public override void VerifyRenderingInServerForm(Control control)
/* Verifies that the control is rendered */
can you advise?
Oct 27, 2016 10:09 AM|av2020|LINK
Managed with "Task Scheduler" with binding the web details,
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
Call objHTTP.Open("GET", url, FALSE)
Oct 27, 2016 11:32 AM|gfw|LINK
Don't make it over complicated, the code can be easy. Create a simple Console app that creates your list of message recipients and sends out the email.
To send the message at the same time every day, use the Windows Task Scheduler. Using a console app instead of a web app will also eliminate any possible timeouts if you have a very large list.
I have been using this very simple method for many years to send email to approximately 3,500 people each day. Each message is sent to an individual email address.
More than just the code to a successful list...
...Make sure that you give recipients the ability to opt out of your list for which you will need a simple web page.
...You also need to invest in an app/Dll to manage bounces - failure to do so will probably result in being blacklisted.
...Find and sign up for various Feed Back Loops [FBL] to handle the issue of a list recipient sending you to their Spam account - it will happen.
Hope this helps
Oct 27, 2016 12:18 PM|av2020|LINK
If you do not mind could share your simple method console app details which i can try my side if that's better,
Oct 28, 2016 10:55 AM|gfw|LINK
Using Visual Studio, start by creating a console app.
Add 2 classes: 1) MailingList.cs to generate your mailing list, and 2) SendDailyEmail.cs to send the messages.
MailingList.cs: Your query is in SQL, mine are in Linq to Sql, but either should work to generate a list of recipients. Just to make sure that there are no duplicates in the list, I also make sure to make the list distinct by email address.
My list contains the recipient's name and email address.
SendDailyEmail.cs: This class calls MailingList and send the message. After getting the list, this class iterates through the list to send the message. As you move through the list, you combine the message and direct it to your email client.
There is s SendEmail method in one of the posts above that should work after you use your server parameters.
In Program.cs (created as the main class in the console app) call SendDailyEmail.
Hope this helps.