Ejemplo n.º 1
0
        public static void SendMessage(SmtpServer server, string from, string to, string subject, string content)
        {
            // compress Foe message and convert the compressed data to Base64 string
            byte[] compressedData = Foe.Common.CompressionManager.Compress(Encoding.UTF8.GetBytes(content));
            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;
            }
        }
        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");
        }
        static void Main(string[] args)
        {
            FoeDebug.Print("Creating Foe Message content.");
            string catalog = "VOAENGLISH";

            FoeDebug.Print("Generating a random request ID.");
            string requestId = RandomString.Generate(10);

            FoeDebug.Print("Setting up SMTP configuration.");
            SmtpServer server = new SmtpServer();
            server.ServerName = "smtp.gmail.com";
            server.Port = 587;
            server.AuthRequired = true;
            server.SslEnabled = true;
            server.UserName = "******";
            server.Password = "******";

            FoeDebug.Print("Sending content request message.");
            string subject = SubjectGenerator.RequestSubject(RequestType.Content, requestId, _userId);
            MessageManager.SendMessage(
                server,
                _userEmail,
                _processorEmail,
                subject,
                catalog);
        }
Ejemplo n.º 4
0
        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;
            }
        }
        static void Main(string[] args)
        {
            FoeDebug.Print("Generating a random request ID.");
            string requestId = RandomString.Generate(10);

            FoeDebug.Print("Setting up SMTP configuration.");
            SmtpServer server = new SmtpServer();
            server.ServerName = "doraemon";
            server.Port = 25;
            server.AuthRequired = true;
            server.SslEnabled = false;
            server.UserName = "******";
            server.Password = "******";

            FoeDebug.Print("Sending registration message.");
            MessageManager.SendMessage(
                server,
                _userEmail,
                _processorEmail,
                SubjectGenerator.RequestSubject(RequestType.Registration, requestId, "Newbie"),
                "");
        }
Ejemplo n.º 6
0
 public static void SetSmtpServer(SmtpServer server)
 {
     FoeClientRegistry.SetEntry("smtpserver", server.ServerName);
     FoeClientRegistry.SetEntry("smtpport", server.Port.ToString());
     FoeClientRegistry.SetEntry("smtpauthrequired", (server.AuthRequired ? "T" : "F"));
     if (server.AuthRequired)
     {
         FoeClientRegistry.SetEntry("smtpsslenabled", (server.SslEnabled ? "T" : "F"));
         FoeClientRegistry.SetEntry("smtpusername", server.UserName);
         FoeClientRegistry.SetEntry("smtppassword", server.UserName);
     }
 }
Ejemplo n.º 7
0
 public static void SendMessage(SmtpServer server, string from, string to, string subject, string content)
 {
     // simply call the SendMessage function in the Common.MessageManager namespace
     Foe.Common.MessageManager.SendMessage(server, from, to, subject, content);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Attempt to get SMTP server information. If no server is available or if information is invalid, then null will be returned.
        /// </summary>
        /// <returns>SmtpServer object if SMTP is configured. Returns null otherwise.</returns>
        public static SmtpServer GetSmtpServer()
        {
            SmtpServer server = new SmtpServer();

            try
            {
                server.ServerName = FoeClientRegistry.GetEntry("smtpserver").Value;
                server.Port = Convert.ToInt32(FoeClientRegistry.GetEntry("smtpport").Value);
                server.AuthRequired = ((FoeClientRegistry.GetEntry("smtpauthrequired").Value == "T") ? true : false);
                if (server.AuthRequired)
                {
                    server.SslEnabled = ((FoeClientRegistry.GetEntry("smtpsslenabled").Value == "T") ? true : false);
                    server.UserName = FoeClientRegistry.GetEntry("smtpusername").Value;
                    server.Password = FoeClientRegistry.GetEntry("smtppassword").Value;
                }
            }
            catch (Exception)
            {
                // Invalid SMTP server configuration
                //throw new Exception("Invalid SMTP server configurations.");
                server = null;
            }

            return server;
        }
Ejemplo n.º 9
0
        public static SmtpServer GetDefaultSmtpServer()
        {
            SmtpServer server = new SmtpServer();

            server.ServerName = FoeServerRegistry.Get("SmtpServerName");
            server.Port = Convert.ToInt32(FoeServerRegistry.Get("SmtpPort"));
            server.AuthRequired = (FoeServerRegistry.Get("SmtpAuthRequired").ToUpper().CompareTo("T") == 0);
            server.SslEnabled = (FoeServerRegistry.Get("SmtpSslEnabled").ToUpper().CompareTo("T") == 0);
            server.UserName = FoeServerRegistry.Get("SmtpUserName");
            server.Password = FoeServerRegistry.Get("SmtpPassword");

            return server;
        }