Exemplo n.º 1
0
        public void Degistir_CC(string DegistirilecekMailAdres, string YeniMailAdres)
        {
            if (string.IsNullOrEmpty(DegistirilecekMailAdres))
            {
                throw new Exception("Değiştirilecek Mail Adresi Boş.");
            }
            if (string.IsNullOrEmpty(YeniMailAdres))
            {
                throw new Exception("Yeni Mail Adresi Boş.");
            }
            if (CC.Contains(YeniMailAdres))
            {
                throw new Exception("Bu Mail Adresi Daha Önce Eklenmiş.");
            }

            if (CC.Contains(DegistirilecekMailAdres))
            {
                Sil_CC(DegistirilecekMailAdres);
                Ekle_CC(YeniMailAdres);
            }
            else
            {
                throw new Exception("Böyle Bir Mail Adresi Bulunamadı.");
            }
        }
Exemplo n.º 2
0
 public void SetUserReadStatus(User user, bool read)
 {
     if (Receivers.Contains(user) || BCC.Contains(user) || CC.Contains(user))
     {
         IsRead[user.Email] = read;
     }
 }
Exemplo n.º 3
0
        public void Sil_CC(string MailAdres)
        {
            if (string.IsNullOrEmpty(MailAdres))
            {
                throw new Exception("Mail Adresi Boş.");
            }

            if (CC.Contains(MailAdres))
            {
                CC.Remove(MailAdres);
            }
        }
Exemplo n.º 4
0
        public void Ekle_CC(string MailAdres)
        {
            if (!Dogrulama.EmailDogrula(MailAdres))
            {
                throw new Exception("Geçersiz Mail Adresi");
            }
            if (CC.Contains(MailAdres))
            {
                throw new Exception("Bu Mail Adresi Daha Önce Eklenmiş.");
            }

            CC.Add(MailAdres);
        }
Exemplo n.º 5
0
		/// <summary>
		/// Sends the email message.
		/// </summary>
		public void Send()
		{
			// Initialize the body from the email template if we don't have a body set
			// and a template filename has been specified.

			if ((Body.Length == 0) && (TemplateFilename.Length > 0))
			{
				string filename = GetPhysicalPath(TemplateFilename);

				if (!File.Exists(filename))
					throw new EmailTemplateNotFoundException(TemplateFilename);

				Body = XmlUtils.Transform(BodyXmlDoc.InnerXml, filename, BodyParameters);
			}

			// Initialize the email message
			MailMessage message = new MailMessage
			{
				From = GetMailAddress(FromEmail, FromName),
				Subject = Subject,
				Body = Body,
				BodyEncoding = Encoding.ASCII,
				IsBodyHtml = IsHtml
			};

			message.Headers.Add("x-sender-application", "FocusOPEN");

			if (HasDebugMode && IsDebugMode)
			{
				// Add debug email addresses
				foreach (string debugEmailAddress in DebugEmail.Split(';').Where(StringUtils.IsEmail))
					message.To.Add(new MailAddress(debugEmailAddress));

				// List of actual recipients
				JoinableList jList = new JoinableList();

				// To recipients
				foreach (string recipient in Recipients)
					jList.Add(recipient);

				// CC recipients
				foreach (string recipient in CC.Where(recipient => !Recipients.Contains(recipient)))
					jList.Add("CC:" + recipient);

				// BCC recipients
				foreach (string recipient in BCC.Where(recipient => !Recipients.Contains(recipient) && !BCC.Contains(recipient)))
					jList.Add("BCC:" + recipient);

				// Build our debug message
				StringBuilder sb = new StringBuilder();

				if (IsHtml)
				{
					// Wrap our debug message in a DIV for better viewing
					sb.Append("<div style='margin:30px 0px 30px 0px;border:2px solid red;background:#eee;padding:10px;color:#000;'>");
					sb.Append("<p><strong>This email has been sent in debug mode.</strong></p>");
					sb.Append("<p><strong>Actual Recipients:</strong></p>");
					sb.Append(jList);
					sb.Append("</div>");
				}
				else
				{
					// Just add a few line breaks for text email messages
					sb.AppendFormat("\n\n\nThis email has been sent in debug mode.  Actual recipients: {0}", jList);
				}

				// Add debug message to the email message body
				message.Body += sb.ToString();
			}
			else
			{
				//---------------------------------------------------
				// Add all recipients
				//---------------------------------------------------

				foreach (string emailaddress in Recipients)
				{
					try
					{
						message.To.Add(emailaddress);
					}
					catch (Exception ex)
					{
						Debug.WriteLine(ex.Message);
					}
				}

				//---------------------------------------------------
				// Add all CC recipients which haven't
				// already been added into the recipients list
				//---------------------------------------------------

				foreach (string emailaddress in CC.Where(emailaddress => !Recipients.Contains(emailaddress)))
				{
					try
					{
						message.CC.Add(emailaddress);
					}
					catch (Exception ex)
					{
						Debug.WriteLine(ex.Message);
					}
				}

				//---------------------------------------------------
				// Add all BCC recipients which haven't
				// already been added into the CC or recipients list
				//---------------------------------------------------

				foreach (string emailaddress in BCC.Where(emailaddress => !Recipients.Contains(emailaddress) && !CC.Contains(emailaddress)))
				{
					try
					{
						message.Bcc.Add(emailaddress);
					}
					catch (Exception ex)
					{
						Debug.WriteLine(ex.Message);
					}
				}

				//---------------------------------------------------
				// Add all static BCC recipients which haven't
				// already been added into any other lists
				//---------------------------------------------------

				if (IncludeStaticBccRecipients)
				{
					foreach (string bccEmailAddress in BccEmail.Split(';').Where(bccEmailAddress => !Recipients.Contains(bccEmailAddress) && !CC.Contains(bccEmailAddress) && !BCC.Contains(bccEmailAddress)))
					{
						try
						{
							message.Bcc.Add(bccEmailAddress);
						}
						catch (Exception ex)
						{
							Debug.WriteLine(ex.Message);
						}
					}
				}
			}

			// Add attachments
			foreach (Attachment attachment in Attachments)
				message.Attachments.Add(attachment);

			// Only send the email message if the email engine is actually enabled
			if (EngineEnabled)
			{
				// Initialize the smtp client to send the email
				SmtpClient client = new SmtpClient(MailServer);

				// Add credentials to authenticate to mail server if required
				if (!StringUtils.IsBlank(MailServerUsername) || !StringUtils.IsBlank(MailServerPassword))
					client.Credentials = new System.Net.NetworkCredential(MailServerUsername, MailServerPassword, MailServerLogonDomain);

				// Send the message
				client.Send(message);
			}
		}