/*
The method sends all orders stored in the database to the test email.
* It uses security context in order to take the current logged user.
*/
public void SendMail()
{
//Create a new smtp client. Set the credentials for the host user.
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("*****@*****.**", "testTechromX123");
// Call the business login in order to take all the order details for the current user.
OrdersBL ordersBl = new OrdersBL();
List<JsonOrderItem> orderItemList = ordersBl.GetAllOrdersDetails( SecurityContext.Current.CurrentUserName);
// Create the string that will be the body of the sended mail by iterating every order element from the taken list.
String bodyString = null;
foreach (var itemOrder in orderItemList)
{
String lineString = null;
lineString = "Owner Name: " + itemOrder.ownerName.ToString() + "\n" + "Expiration Data: " + itemOrder.expData.ToString() + "\n" +
"Tracking Number: " + itemOrder.tranckingNumber.ToString() + "\n" + "Total Number Of Items: " + itemOrder.totalAmmountItems.ToString() +"\n"+
"Total Sum " + itemOrder.totalAmmountSum.ToString() + itemOrder.currency.ToString() + "\n";
bodyString += "\n" + lineString;
}
//Sends the mail to the implicit writed test account.
MailMessage mm = new MailMessage("*****@*****.**", "*****@*****.**", "YourEpiServerOrder", bodyString);
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.Send(mm);
}