Beispiel #1
0
        public void Add(MailMessage mail, SmtpClient smtp)
        {
            Email email = new Email();

            email.DataInclusao = DateTime.Now;
            email.Assunto = mail.Subject;
            email.Corpo = mail.Body;
            email.CorpoHtml = mail.IsBodyHtml;
            email.De = mail.From.DisplayName;
            email.DeEmail = mail.From.Address;
            email.Encode = mail.BodyEncoding.WebName;
            email.Host = smtp.Host;
            email.Porta = smtp.Port.ToString();
            email.SmtpAutenticado = !smtp.UseDefaultCredentials;

            if (!smtp.UseDefaultCredentials && smtp.Credentials != null)
            {
                email.SmtpUsuario = ((NetworkCredential)smtp.Credentials).UserName;
                email.SmtpSenha = ((NetworkCredential)smtp.Credentials).Password;
            }

            email.SslHabilitado = smtp.EnableSsl;

            db.Emails.InsertOnSubmit(email);

            this.Save();

            if (mail.To != null)
            {
                foreach (var destinatario in mail.To)
                {
                    EmailDestinatario emailDestinatario = new EmailDestinatario();

                    emailDestinatario.Email = destinatario.Address;
                    emailDestinatario.Nome = destinatario.DisplayName;
                    emailDestinatario.Tipo = (Char)Email.EnumTipo.Destinatario;
                    emailDestinatario.IdEmail = email.Id;

                    db.EmailDestinatarios.InsertOnSubmit(emailDestinatario);
                }
            }

            if (mail.CC != null)
            {
                foreach (var destinatario in mail.CC)
                {
                    EmailDestinatario emailDestinatario = new EmailDestinatario();

                    emailDestinatario.Email = destinatario.Address;
                    emailDestinatario.Nome = destinatario.DisplayName;
                    emailDestinatario.Tipo = (Char)Email.EnumTipo.Copia;
                    emailDestinatario.IdEmail = email.Id;

                    db.EmailDestinatarios.InsertOnSubmit(emailDestinatario);
                }
            }

            if (mail.Bcc != null)
            {
                foreach (var destinatario in mail.Bcc)
                {
                    EmailDestinatario emailDestinatario = new EmailDestinatario();

                    emailDestinatario.Email = destinatario.Address;
                    emailDestinatario.Nome = destinatario.DisplayName;
                    emailDestinatario.Tipo = (Char)Email.EnumTipo.CopiaOculta;
                    emailDestinatario.IdEmail = email.Id;

                    db.EmailDestinatarios.InsertOnSubmit(emailDestinatario);
                }
            }
        }
Beispiel #2
0
 partial void DeleteEmailDestinatario(EmailDestinatario instance);
Beispiel #3
0
 partial void InsertEmailDestinatario(EmailDestinatario instance);
Beispiel #4
0
 partial void UpdateEmailDestinatario(EmailDestinatario instance);
Beispiel #5
0
		private void detach_EmailDestinatarios(EmailDestinatario entity)
		{
			this.SendPropertyChanging();
			entity.Email1 = null;
		}