示例#1
0
        internal static void SendEmail(OutgoingMail entity, byte[] attachment = null, string attachmentName = null)
        {
            var settings = GetSettings();

            if (settings == null)
            {
                entity.Result = "Keine gültigen SMTP-Daten.";
                return;
            }

            using (SmtpClient client = new SmtpClient(settings.Host, settings.Port))
            {
                try
                {
                    client.UseDefaultCredentials = false;
                    client.Credentials           = new NetworkCredential(settings.User, settings.Pass);
                    MailMessage message = new MailMessage(settings.Sender, entity.Recipient, entity.Subject, entity.Body);
                    message.IsBodyHtml = false;

                    if ((attachment != null) && !String.IsNullOrWhiteSpace(attachmentName))
                    {
                        using (MemoryStream ms = new MemoryStream(attachment))
                            message.Attachments.Add(new Attachment(ms, attachmentName));
                    }

                    client.Send(message);
                    entity.Result = "Ok";
                }
                catch (Exception ex)
                {
                    entity.Result = ex.Message;
                }
            }
        }
示例#2
0
		internal static void SendEmail(OutgoingMail entity, byte[] attachment = null, string attachmentName = null)
		{
			var settings = GetSettings();
			if (settings == null)
			{
				entity.Result = "Keine gültigen SMTP-Daten.";
				return;
			}

			using (SmtpClient client = new SmtpClient(settings.Host, settings.Port))
			{
				try
				{
					client.UseDefaultCredentials = false;
					client.Credentials = new NetworkCredential(settings.User, settings.Pass);
					MailMessage message = new MailMessage(settings.Sender, entity.Recipient, entity.Subject, entity.Body);
					message.IsBodyHtml = false;

					if ((attachment != null) && !String.IsNullOrWhiteSpace(attachmentName))
						using (MemoryStream ms = new MemoryStream(attachment))
							message.Attachments.Add(new Attachment(ms, attachmentName));

					client.Send(message);
					entity.Result = "Ok";
				}
				catch (Exception ex)
				{
					entity.Result = ex.Message;
				}
			}
		}
 // E-MAIL
 partial void OutgoingMailSet_Inserting(OutgoingMail entity)
 {
     entity.Sended = DateTime.Now;
     SmtpSender.SendEmail(entity);
 }
		// E-MAIL
		partial void OutgoingMailSet_Inserting(OutgoingMail entity)
		{
			entity.Sended = DateTime.Now;
			SmtpSender.SendEmail(entity);
		}