Ejemplo n.º 1
0
 public static MailMessage Convert(SerializableMailMessage n)
 {
     var retval = new MailMessage { Body = n.Body, From = new MailAddress(n.From), Subject = n.Subject, IsBodyHtml = n.IsBodyHtml };
     foreach (var address in n.To)
         retval.To.Add(address);
     return retval;
 }
Ejemplo n.º 2
0
        public override void AddEmail(MailMessage email)
        {
            using (SqlConnection connection = new SqlConnection(this._connectionString))
            {
                SqlCommand command = new SqlCommand("gopi_AddEmail", connection);
                command.CommandType = CommandType.StoredProcedure;

                SerializableMailMessage mailToSerialize = new SerializableMailMessage();
                mailToSerialize.Email = email;

                XmlSerializer serializer = new XmlSerializer(typeof(SerializableMailMessage));
                using (StringWriter writer = new StringWriter())
                {
                    serializer.Serialize(writer, mailToSerialize);

                    command.Parameters.AddWithValue("EmailData",
                        writer.GetStringBuilder().ToString());
                }

                connection.Open();
                command.ExecuteNonQuery();
                connection.Close();
                command.Dispose();
            }
        }
Ejemplo n.º 3
0
 public static SerializableMailMessage Convert(MailMessage n)
 {
     var retval = new SerializableMailMessage { Body = n.Body, To = new List<string>(), From = n.From.Address, Subject = n.Subject, IsBodyHtml = n.IsBodyHtml };
     foreach (var to in n.To)
         retval.To.Add(to.Address);
     return retval;
 }
Ejemplo n.º 4
0
        public override MailCollection GetEmails(int emailsCount)
        {
            MailCollection emails = new MailCollection();

            using (SqlConnection connection = new SqlConnection(this._connectionString))
            {
                SqlCommand command = new SqlCommand("gopi_GetEmails", connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("Count", emailsCount);

                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(SerializableMailMessage));
                    while (reader.Read())
                    {
                        SerializableMailMessage email = new SerializableMailMessage();

                        string stringData = (string)reader["EmailData"];
                        MemoryStream memoryStream = new MemoryStream();
                        byte[] data = Encoding.Unicode.GetBytes(stringData);
                        Encoding.Convert(Encoding.Default, Encoding.UTF8, data);
                        memoryStream.Write(data, 0, data.Length);

                        memoryStream.Position = 0;

                        email = (SerializableMailMessage)serializer.Deserialize(memoryStream);

                        email.ID = new Guid(reader["ID"].ToString());
                        email.DateAdded = (DateTime)reader["DateAdded"];

                        emails.Add(email);
                    }
                }

                connection.Close();
                command.Dispose();
            }

            return emails;
        }