Hi all, I have some questions that i am unsure of. Currently I am working on a project, that i need to send email notifications to a user email via Visual Studio 2012. So, I have this web storage called Xively, whereby I want to set my criteria on when the email will be sent. Is that possible?
My codes are as follows;
private void getDatastreamLatestTimestamp(string requestURL)
{
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Singapore Standard Time");
DateTime dt = TimeZoneInfo.ConvertTime(DateTime.Now, timeZoneInfo);
string jsonString = HttpRequest.getRequest(requestURL, null);
if (jsonString != null)
{
Datastream ds = JsonConvert.DeserializeObject<Datastream>(jsonString);
DateTime dsTimestamp = TimeZoneInfo.ConvertTime(Convert.ToDateTime(ds.at), timeZoneInfo);
// Compare current datetime with Xively retrieved datetime,
// send out email if difference is more than 2 hours
if (dt.Subtract(dsTimestamp).Hours >= 2)
{
sendEmail();
}
}
}
// Method for sending out email via Gmail service
private void sendEmail()
{
Debug.Print("Sending out email...");
var fromAddress = new MailAddress("12345@gmail.com", "Motion Sensor Web Monitoring");
var toAddress = new MailAddress("121212@gmail.com", "Whom It May Concern");
const string fromPassword = "administrator";
const string subject = "Unusual Motion Timing";
const string body = "Hi, there has been unusual motion timing detected, kindly take note.";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
}
My codes are as follows;
private void getDatastreamLatestTimestamp(string requestURL)
{
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Singapore Standard Time");
DateTime dt = TimeZoneInfo.ConvertTime(DateTime.Now, timeZoneInfo);
string jsonString = HttpRequest.getRequest(requestURL, null);
if (jsonString != null)
{
Datastream ds = JsonConvert.DeserializeObject<Datastream>(jsonString);
DateTime dsTimestamp = TimeZoneInfo.ConvertTime(Convert.ToDateTime(ds.at), timeZoneInfo);
// Compare current datetime with Xively retrieved datetime,
// send out email if difference is more than 2 hours
if (dt.Subtract(dsTimestamp).Hours >= 2)
{
sendEmail();
}
}
}
// Method for sending out email via Gmail service
private void sendEmail()
{
Debug.Print("Sending out email...");
var fromAddress = new MailAddress("12345@gmail.com", "Motion Sensor Web Monitoring");
var toAddress = new MailAddress("121212@gmail.com", "Whom It May Concern");
const string fromPassword = "administrator";
const string subject = "Unusual Motion Timing";
const string body = "Hi, there has been unusual motion timing detected, kindly take note.";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
}