示例#1
0
        private static void SendMail(OrderInfo order, string to, string @from, string subject, string body, string nameFrom)
        {
            try
            {
                if (string.IsNullOrEmpty(nameFrom))
                {
                    nameFrom = @from;
                }
                var msg = new MailMessage {
                    From = new MailAddress(from, nameFrom), Subject = subject, Body = body, IsBodyHtml = true
                };

                msg.To.Add(new MailAddress(to));

                var client = new SmtpClient();

                Log.Instance.LogDebug("SendMail before send event");
                if (BeforeSendEmail != null)
                {
                    var beforeSendEmailEventArgs = new BeforeSendEmailEventArgs {
                        Order = order, Email = new UwebshopEmailAdaptor(msg)
                    };

                    BeforeSendEmail(beforeSendEmailEventArgs);
                }
                Log.Instance.LogDebug("SendMail before client.send");
                client.Send(msg);
                Log.Instance.LogDebug("SendMail after client.send");
            }
            catch (Exception ex)
            {
                Log.Instance.LogError("The following error occured while trying to send the " + subject + " e-mail: " + ex);
            }
        }
示例#2
0
		private static void SendMail(OrderInfo order, string to, string @from, string subject, string body, string nameFrom)
		{
			try
			{
				if (string.IsNullOrEmpty(nameFrom))
				{
					nameFrom = @from;
				}
				var msg = new MailMessage {From = new MailAddress(from, nameFrom), Subject = subject, Body = body, IsBodyHtml = true};
				
				msg.To.Add(new MailAddress(to));

				var client = new SmtpClient();

				Log.Instance.LogDebug("SendMail before send event");
				if (BeforeSendEmail != null)
				{
					var beforeSendEmailEventArgs = new BeforeSendEmailEventArgs {Order = order, Email = new UwebshopEmailAdaptor(msg)};

					BeforeSendEmail(beforeSendEmailEventArgs);
				}
				Log.Instance.LogDebug("SendMail before client.send");
				client.Send(msg);
				Log.Instance.LogDebug("SendMail after client.send");
			}
			catch (Exception ex)
			{
				Log.Instance.LogError("The following error occured while trying to send the " + subject + " e-mail: " + ex);
			}
		}