static void TestFoeMessageToXml() { PrintTitle("Testing FoeMessage.ToXml()"); FoeMessage message = new FoeMessage(); string[,] data = new string[3, 2] { { "RequestId", "12345" }, { "UserId", "ABCDE" }, { "Request", "RFACHINESE" } }; for (int i = 0; i < 3; i++) { FoeMessageItem item = new FoeMessageItem(data[i, 0], data[i, 1]); message.Add(item); } Console.WriteLine(message.ToXml()); // test send email Console.WriteLine("Sending message to [email protected]..."); SmtpServer server = new SmtpServer(); server.ServerName = "smtp.gmail.com"; server.Port = 587; server.AuthRequired = true; server.SslEnabled = true; server.UserName = "******"; server.Password = "******"; MessageManager.SendMessage(server, "*****@*****.**", "*****@*****.**", "Test Message", message); Console.WriteLine("Message sent"); }
public static void SendMessage(SmtpServer server, string from, string to, string subject, FoeMessage message) { // compress Foe message and convert the compressed data to Base64 string byte[] compressedData = Foe.Common.CompressionManager.Compress(Encoding.UTF8.GetBytes(message.ToXml())); string based64 = Convert.ToBase64String(compressedData); // send email try { // create mail MailMessage mail = new MailMessage(from, to, subject, based64); // connect and send SmtpClient smtp = new SmtpClient(server.ServerName, server.Port); if (server.AuthRequired) { smtp.EnableSsl = server.SslEnabled; smtp.UseDefaultCredentials = false; NetworkCredential cred = new NetworkCredential(server.UserName, server.Password); smtp.Credentials = cred; } smtp.Send(mail); } catch (Exception except) { throw except; } }
public Form1() { InitializeComponent(); // generate a sample message FoeMessage msg = new FoeMessage(); msg.Add(new FoeMessageItem("RequestType", "RssFeed")); msg.Add(new FoeMessageItem("FeedId", "VOACHINESE")); tbxSource.Text = msg.ToXml(); }
public static void SendRegistration() { // Check if user's email is available FoeClientRegistryEntry email = FoeClientRegistry.GetEntry("useremail"); if ((email == null) || (email.Value == null) || (email.Value.Length < 3)) { // Invalid user email return; } // Prepare message to send to server FoeMessage message = new FoeMessage(); message.Add(new FoeMessageItem("UserEmail", email.Value)); // Get SMTP server configurations SmtpServer server = null; try { server = FoeClientMessage.GetSmtpServer(); } catch (Exception except) { throw new Exception("Invalid SMTP configurations.\r\n" + except.ToString()); } // Send email try { string requestId = FoeClientRequest.GenerateId(); FoeClientMessage.SendMessage( server, email.Value, FoeClientRegistry.GetEntry("processoremail").Value, SubjectGenerator.RequestSubject(RequestType.Registration, requestId, "Newbie"), message); // Save request info FoeClientRequestItem req = new FoeClientRequestItem(); req.Id = requestId; req.Type = "reg"; req.DtRequested = DateTime.Now; FoeClientRequest.Add(req); } catch (Exception except) { throw new Exception("Error sending message.\r\n" + except.ToString()); } }
static void TestFoeMessageImportXml() { PrintTitle("Testing FoeMessage.ImportXml()"); FoeMessage message = new FoeMessage(); string[,] data = new string[3, 2] { { "RequestId", "12345" }, { "UserId", "ABCDE" }, { "Request", "RFACHINESE" } }; for (int i = 0; i < 3; i++) { FoeMessageItem item = new FoeMessageItem(data[i, 0], data[i, 1]); message.Add(item); } message.ImportXml(message.ToXml()); Console.WriteLine(message.ToXml()); }
public static void SendMessage(SmtpServer server, string from, string to, string subject, FoeMessage message) { // simply call the SendMessage function in the Common.MessageManager namespace Foe.Common.MessageManager.SendMessage(server, from, to, subject, message); }
private void SendSubscriptionRequest() { try { // Delete all previous content requests FoeClientRequest.DeleteOldRequest(_requestInterval); // Create Foe Message FoeMessage message = new FoeMessage(); List<FoeClientCatalogItem> catalog = FoeClientCatalog.GetAll(); foreach (FoeClientCatalogItem item in catalog) { if (item.IsSubscribed) { message.Add(new FoeMessageItem("CatalogCode", item.Code)); } } string requestId = FoeClientRequest.GenerateId(); FoeClientMessage.SendMessage( FoeClientMessage.GetSmtpServer(), FoeClientRegistry.GetEntry("useremail").Value, FoeClientRegistry.GetEntry("processoremail").Value, SubjectGenerator.RequestSubject(RequestType.Content, requestId, FoeClientRegistry.GetEntry("userid").Value), message); // save requestid to DB FoeClientRequestItem reqItem = new FoeClientRequestItem(); reqItem.Id = requestId; reqItem.Type = "content"; reqItem.DtRequested = DateTime.Now; FoeClientRequest.Add(reqItem); // remember when the request was sent _lastRequestSent = DateTime.Now; // Set status tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " requested update."; } catch (Exception) { tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " error sending request."; } }