示例#1
0
        private static void CheckIfMailsHaveToBeSend()
        {
            logger.Info("check if mails have to be sent.");

            MongoServer   mongoServer   = MyMongoDB.GetServer();
            MongoDatabase mongoDatabase = mongoServer.GetDatabase("email");
            MongoCollection <LazyBsonDocument> mongoCollection = mongoDatabase.GetCollection <LazyBsonDocument>("users");

            MongoCursor <LazyBsonDocument> mongoCursor = mongoCollection.FindAll();

            foreach (LazyBsonDocument bsonDocument in mongoCursor)
            {
                if (Options.Verbose)
                {
                    Console.WriteLine("checking user-id: " + bsonDocument["_id"].ToString() + "; username: "******"Username"].ToString());
                }

                try {
                    MongoDatabase mongoUserDatabase = mongoServer.GetDatabase("email_user_" + bsonDocument["_id"].ToString());
                    MongoCollection <LazyBsonDocument> mongoUserCollection = mongoUserDatabase.GetCollection <LazyBsonDocument>("mails");
                    MongoCursor <LazyBsonDocument>     mongoUserCursor     = mongoUserCollection.Find(Query.EQ("Folder", "SENT"));
                    foreach (LazyBsonDocument bsonUserDocument in mongoUserCursor)
                    {
                        Console.WriteLine("found email in SENT-Folder: " + bsonUserDocument["_id"].ToString());
                        eMail userMail = new eMail(bsonUserDocument);
                        userMail.Send();
                        break;
                    }
                } catch (Exception ex) {
                    logger.ErrorException(ex.Message, ex);
                }
            }
        }
示例#2
0
        private void Mail(string rawUrl, NameValueCollection queryString)
        {
            if (!this.User.IsLoggedIn)
            {
                throw new UnauthorizedAccessException("access denied");
            }

            XmlNode    XmlRoot = this._doc.GetElementsByTagName(this._xmlRoot).Item(0);
            XmlElement XmlMail = this._doc.CreateElement("mail");

            rawUrl = Regex.Replace(rawUrl.Replace("/mail/", ""), "\\?.*", "", RegexOptions.Compiled);
            switch (rawUrl)
            {
            case "get":
                if (queryString["id"] != null && queryString["id"] != String.Empty)
                {
                    eMail mail = this.User.GetEMail(queryString["id"]);
                    if (mail != null)
                    {
                        XmlMail.SetAttribute("from", mail.MailFrom);
                        XmlMail.SetAttribute("to", mail.RecipientTo);
                        XmlMail.SetAttribute("subject", mail.Subject);

                        XmlElement XmlRecipients = this._doc.CreateElement("recipients");
                        XmlMail.AppendChild(XmlRecipients);

                        XmlElement XmlMessage = this._doc.CreateElement("message");
                        XmlMessage.InnerText = mail.Message;
                        XmlMail.AppendChild(XmlMessage);
                    }
                }
                break;

            case "write":
                if (this.Request.HttpMethod == "POST")
                {
                    using (HttpPostRequest.HttpPostRequest postRequest = new HttpPostRequest.HttpPostRequest(this.Request)) {
                        string toEMail = String.Empty;
                        string subject = String.Empty;
                        string message = String.Empty;

                        if (postRequest.Parameters["email"] != null)
                        {
                            toEMail = postRequest.Parameters["email"];
                        }
                        if (postRequest.Parameters["subject"] != null)
                        {
                            subject = postRequest.Parameters["subject"];
                        }
                        if (postRequest.Parameters["message"] != null)
                        {
                            message = postRequest.Parameters["message"];
                        }

                        eMail newEMail = new eMail();
                        newEMail.SetFrom(this.User.eMail);
                        newEMail.SetRecipient(toEMail);
                        newEMail.SetSubject(subject);
                        newEMail.SetMessage(message);

                        XmlMail.SetAttribute("from", newEMail.MailFrom);
                        XmlMail.SetAttribute("to", newEMail.RecipientTo);
                        XmlMail.SetAttribute("subject", newEMail.Subject);

                        XmlElement XmlRecipients = this._doc.CreateElement("recipients");

                        /*
                         * foreach(string recipient in newEMail.Recipients) {
                         *      XmlElement XmlRecipient = this._doc.CreateElement("recipient");
                         *      XmlRecipient.SetAttribute("email", recipient);
                         *      XmlRecipients.AppendChild(XmlRecipient);
                         * }
                         */
                        XmlMail.AppendChild(XmlRecipients);

                        XmlElement XmlMessage = this._doc.CreateElement("message");
                        XmlMessage.InnerText = newEMail.Message;
                        XmlMail.AppendChild(XmlMessage);

                        this.User.AddEMail(newEMail);
                        newEMail.Send();
                    }
                }
                break;
            }

            XmlRoot.AppendChild(XmlMail);
        }
		private void Mail(string rawUrl, NameValueCollection queryString) {
			if (!this.User.IsLoggedIn) {
				throw new UnauthorizedAccessException("access denied");
			}

			XmlNode XmlRoot = this._doc.GetElementsByTagName(this._xmlRoot).Item(0);
			XmlElement XmlMail = this._doc.CreateElement("mail");

			rawUrl = Regex.Replace(rawUrl.Replace("/mail/", ""), "\\?.*", "", RegexOptions.Compiled);
			switch(rawUrl) {
				case "get":
					if (queryString["id"] != null && queryString["id"] != String.Empty) {
						eMail mail = this.User.GetEMail(queryString["id"]);
						if (mail != null) {
							XmlMail.SetAttribute("from", mail.MailFrom);
							XmlMail.SetAttribute("to", mail.RecipientTo);
							XmlMail.SetAttribute("subject", mail.Subject);

							XmlElement XmlRecipients = this._doc.CreateElement("recipients");
							XmlMail.AppendChild(XmlRecipients);

							XmlElement XmlMessage = this._doc.CreateElement("message");
							XmlMessage.InnerText = mail.Message;
							XmlMail.AppendChild(XmlMessage);
						}
					}
					break;

				case "write":
					if (this.Request.HttpMethod == "POST") {
						using(HttpPostRequest.HttpPostRequest postRequest = new HttpPostRequest.HttpPostRequest(this.Request)) {
							string toEMail = String.Empty;
							string subject = String.Empty;
							string message = String.Empty;

							if (postRequest.Parameters["email"] != null) {
								toEMail = postRequest.Parameters["email"];
							}
							if (postRequest.Parameters["subject"] != null) {
								subject = postRequest.Parameters["subject"];
							}
							if (postRequest.Parameters["message"] != null) {
								message = postRequest.Parameters["message"];
							}

							eMail newEMail = new eMail();
							newEMail.SetFrom(this.User.eMail);
							newEMail.SetRecipient(toEMail);
							newEMail.SetSubject(subject);
							newEMail.SetMessage(message);

							XmlMail.SetAttribute("from", newEMail.MailFrom);
							XmlMail.SetAttribute("to", newEMail.RecipientTo);
							XmlMail.SetAttribute("subject", newEMail.Subject);

							XmlElement XmlRecipients = this._doc.CreateElement("recipients");
							/*
							foreach(string recipient in newEMail.Recipients) {
								XmlElement XmlRecipient = this._doc.CreateElement("recipient");
								XmlRecipient.SetAttribute("email", recipient);
								XmlRecipients.AppendChild(XmlRecipient);
							}
							*/
							XmlMail.AppendChild(XmlRecipients);

							XmlElement XmlMessage = this._doc.CreateElement("message");
							XmlMessage.InnerText = newEMail.Message;
							XmlMail.AppendChild(XmlMessage);

							this.User.AddEMail(newEMail);
							newEMail.Send();
						}
					}
					break;
			}

			XmlRoot.AppendChild(XmlMail);
		}
示例#4
0
		private static void CheckIfMailsHaveToBeSend() {
			logger.Info("check if mails have to be sent.");

			MongoServer mongoServer = MyMongoDB.GetServer();
			MongoDatabase mongoDatabase = mongoServer.GetDatabase("email");
			MongoCollection<LazyBsonDocument> mongoCollection = mongoDatabase.GetCollection<LazyBsonDocument>("users");

			MongoCursor<LazyBsonDocument> mongoCursor = mongoCollection.FindAll();
			foreach(LazyBsonDocument bsonDocument in mongoCursor) {
				if (Options.Verbose) {
					Console.WriteLine("checking user-id: " + bsonDocument["_id"].ToString() + "; username: "******"Username"].ToString());
				}

				try {
					MongoDatabase mongoUserDatabase = mongoServer.GetDatabase("email_user_" + bsonDocument["_id"].ToString());
					MongoCollection<LazyBsonDocument> mongoUserCollection = mongoUserDatabase.GetCollection<LazyBsonDocument>("mails");
					MongoCursor<LazyBsonDocument> mongoUserCursor = mongoUserCollection.Find(Query.EQ("Folder", "SENT"));
					foreach(LazyBsonDocument bsonUserDocument in mongoUserCursor) {
						Console.WriteLine("found email in SENT-Folder: " + bsonUserDocument["_id"].ToString());
						eMail userMail = new eMail(bsonUserDocument);
						userMail.Send();
						break;
					}
				} catch(Exception ex) {
					logger.ErrorException(ex.Message, ex);
				}
			}
		}