コード例 #1
0
        internal static Pop3Message Create(string From, string[] To, string Subject, string Body, Mediachase.IBN.Business.ControlSystem.DirectoryInfo Attachments)
        {
            MemoryStream emlMessage = new MemoryStream();

            byte[] tmpBuffer = null;

            string ToEmail = string.Join(", ", To);

            #region Fill Pop3 Message Stream
            // Create Pop3 Message Headers
            StringBuilder sbHeaders = new StringBuilder();

            sbHeaders.AppendFormat("Date: {0}", DateTime.UtcNow.ToString("r")).Append("\r\n");

            sbHeaders.AppendFormat("From: {0}", Rfc822HeaderCollection.Encode2AsciiString(From)).Append("\r\n");
            sbHeaders.AppendFormat("To: {0}", Rfc822HeaderCollection.Encode2AsciiString(ToEmail)).Append("\r\n");

            sbHeaders.AppendFormat("Subject: {0}", Rfc822HeaderCollection.Encode2AsciiString(Subject)).Append("\r\n");
            sbHeaders.Append("MIME-Version: 1.0").Append("\r\n");
            sbHeaders.Append("Content-Type: multipart/mixed; boundary=\"----------7E143249668A83E\"").Append("\r\n");
            sbHeaders.Append("\r\n");

            tmpBuffer = Encoding.ASCII.GetBytes(sbHeaders.ToString());
            emlMessage.Write(tmpBuffer, 0, tmpBuffer.Length);

            // Create Pop3 Message Entry
            StringBuilder sbMessage = new StringBuilder();

            sbMessage.Append("------------7E143249668A83E").Append("\r\n");

            // IF MESSAGE IS PLAIN TEXT
            //sbMessage.Append("Content-Type: text/plain; charset=utf-8").Append("\r\n");

            // IF MESSAGE IS HTML TEXT
            sbMessage.Append("Content-Type: text/html; charset=utf-8").Append("\r\n");

            sbMessage.Append("Content-Transfer-Encoding: base64").Append("\r\n");
            sbMessage.Append("\r\n");

            string FullMessage = Body;

            sbMessage.Append(Convert.ToBase64String(Encoding.UTF8.GetBytes(FullMessage), Base64FormattingOptions.InsertLineBreaks)).Append("\r\n");

            tmpBuffer = Encoding.ASCII.GetBytes(sbMessage.ToString());
            emlMessage.Write(tmpBuffer, 0, tmpBuffer.Length);

            if (Attachments != null)
            {
                Hashtable contentTypeHash = new Hashtable();

                using (IDataReader reader = ContentType.GetListContentTypes())
                {
                    while (reader.Read())
                    {
                        contentTypeHash.Add(((string)reader["Extension"]).ToLower(), (string)reader["ContentTypeString"]);
                    }
                }

                // Add Pop3 Message Attachements
                foreach (Mediachase.IBN.Business.ControlSystem.FileInfo fileInfo in Attachments.GetFiles())
                {
                    StringBuilder sbFile = new StringBuilder();

                    sbFile.Append("------------7E143249668A83E").Append("\r\n");
                    sbFile.AppendFormat("Content-Type: {0}; name=\"{1}\"", fileInfo.FileBinaryContentType, Rfc822HeaderCollection.Encode2AsciiString(fileInfo.Name)).Append("\r\n");
                    sbFile.Append("Content-Transfer-Encoding: base64").Append("\r\n");
                    sbFile.AppendFormat("Content-Disposition: attachment; filename=\"{0}\"", Rfc822HeaderCollection.Encode2AsciiString(fileInfo.Name)).Append("\r\n");
                    sbFile.Append("\r\n");

                    using (MemoryStream fs = new MemoryStream())
                    {
                        FileStorage.LightLoadFile(fileInfo, fs);
                        fs.Capacity = (int)fs.Length;

                        sbFile.Append(Convert.ToBase64String(fs.GetBuffer(), Base64FormattingOptions.InsertLineBreaks));
                    }

                    sbFile.Append("\r\n");

                    tmpBuffer = Encoding.ASCII.GetBytes(sbFile.ToString());
                    emlMessage.Write(tmpBuffer, 0, tmpBuffer.Length);
                }
            }

            // Add Final Line
            tmpBuffer = Encoding.ASCII.GetBytes("------------7E143249668A83E--\r\n\r\n");
            emlMessage.Write(tmpBuffer, 0, tmpBuffer.Length);

            #endregion

            return(new Pop3Message(emlMessage));
        }
コード例 #2
0
        /// <summary>
        /// Sends the auto reply.
        /// </summary>
        /// <param name="IncidentId">The incident id.</param>
        /// <param name="From">From.</param>
        /// <param name="To">To.</param>
        internal static void SendAutoReply(int IncidentId, string From, string To)
        {
            IncidentBox incidentBox = IncidentBox.Load(Incident.GetIncidentBox(IncidentId));

            if (!incidentBox.Document.EMailRouterBlock.SendAutoReply)
            {
                return;
            }

            Alerts2.Message msg = Alerts2.GetMessage(incidentBox.Document.GeneralBlock.AutoReplyEMailSubjectTemplate,
                                                     incidentBox.Document.GeneralBlock.AutoReplyEMailBodyTemplate,
                                                     SystemEventTypes.Issue_Created,
                                                     IncidentId, null,
                                                     -1,
                                                     Security.CurrentUser.UserID);

            string subject = msg.Subject, body = msg.Body;

            MemoryStream emlMessage = new MemoryStream();

            byte[] tmpBuffer = null;

            #region Fill Pop3 Message Stream
            // Create Pop3 Message Headers
            StringBuilder sbHeaders = new StringBuilder();

            sbHeaders.AppendFormat("Date: {0}", GetEMailCreationDate()).Append("\r\n");
            sbHeaders.Append("From: [email protected]").Append("\r\n");
            sbHeaders.Append("To: [email protected]").Append("\r\n");
            sbHeaders.AppendFormat("Subject: {0}", Rfc822HeaderCollection.Encode2AsciiString(subject)).Append("\r\n");
            sbHeaders.Append("MIME-Version: 1.0").Append("\r\n");
            sbHeaders.Append("Content-Type: multipart/mixed; boundary=\"----------7E143249668A83E\"").Append("\r\n");
            sbHeaders.Append("\r\n");

            tmpBuffer = Encoding.ASCII.GetBytes(sbHeaders.ToString());
            emlMessage.Write(tmpBuffer, 0, tmpBuffer.Length);

            // Create Pop3 Message Entry
            StringBuilder sbMessage = new StringBuilder();

            sbMessage.Append("------------7E143249668A83E").Append("\r\n");

            // IF MESSAGE IS PLAIN TEXT
            //sbMessage.Append("Content-Type: text/plain; charset=utf-8").Append("\r\n");

            // IF MESSAGE IS HTML TEXT
            sbMessage.Append("Content-Type: text/html; charset=utf-8").Append("\r\n");

            sbMessage.Append("Content-Transfer-Encoding: base64").Append("\r\n");
            sbMessage.Append("\r\n");

            // OZ Fixed 500 5.3.3 Line too long (in reply to end of DATA command)
            sbMessage.Append(Convert.ToBase64String(Encoding.UTF8.GetBytes(body), Base64FormattingOptions.InsertLineBreaks)).Append("\r\n");

            tmpBuffer = Encoding.ASCII.GetBytes(sbMessage.ToString());
            emlMessage.Write(tmpBuffer, 0, tmpBuffer.Length);

            // Add Final Line
            tmpBuffer = Encoding.ASCII.GetBytes("------------7E143249668A83E--\r\n\r\n");
            emlMessage.Write(tmpBuffer, 0, tmpBuffer.Length);

            #endregion

            Pop3Message InMsg = new Pop3Message(emlMessage);

            OutputMessageCreator outputAutoReply = new OutputMessageCreator(InMsg, IncidentId, From, From);
            outputAutoReply.AddRecipient(To);

            int emailBoxId = EMail.EMailRouterOutputMessage.FindEMailRouterPublicId(IncidentId);

            foreach (OutputMessage outputMsg in outputAutoReply.Create())
            {
                try
                {
                    SmtpClientUtility.SendMessage(OutgoingEmailServiceType.HelpDeskEmailBox, emailBoxId, outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex);
                    Log.WriteError(ex.ToString());
                }
            }
        }
コード例 #3
0
ファイル: MHTHelper.cs プロジェクト: alex765022/IBN
        protected void SaveHeaders(System.IO.StreamWriter writer, Rfc822HeaderCollection headers)
        {
            StringBuilder stringBuilder = new StringBuilder(30 * headers.Count);

            //			for (int i = 0; i < headers.Count; i++)
            //			{
            //				string str1 = headers.GetKey(i);
            //				string str2 = headers.Get(i);
            //
            //				if(str1=="Content-Transfer-Encoding")
            //					continue;
            //
            //				str2 = str2.Replace("text/plain","text/html");
            //
            //				if(str2.IndexOf("charset")!=-1)
            //				{
            //					int iCharSetIndex = str2.IndexOf("charset");
            //					int iStartIndex = str2.IndexOf("=",iCharSetIndex);
            //					int iEndIndex = str2.IndexOf(";",iStartIndex);
            //					if(iEndIndex==-1)
            //						iEndIndex = str2.Length;
            //
            //					string CharSet = str2.Substring(iStartIndex+1,iEndIndex-iStartIndex-1);
            //					str2 = str2.Replace(CharSet,"\"utf-8\"");
            //				}
            //
            //				stringBuilder.Append(str1).Append(": ");
            //				stringBuilder.Append(str2).Append("\r\n");
            //			}

            if (headers["Content-Type"] == null)
            {
                stringBuilder.Append("Content-Type").Append(": ");
                stringBuilder.Append("text/html; charset=\"utf-8\"").Append("\r\n");
            }
            else
            {
                stringBuilder.Append("Content-Type").Append(": ");

                string strContentTypeValue = headers["Content-Type"];

                if (!_HasHtmlMessage)
                {
                    strContentTypeValue = strContentTypeValue.Replace("text/plain", "text/html");
                }

                ///strContentTypeValue = ChangeCharset(strContentTypeValue);

                stringBuilder.Append(strContentTypeValue).Append("\r\n");
            }

            stringBuilder.Append("Content-Transfer-Encoding").Append(": ");
            stringBuilder.Append("base64").Append("\r\n");

            if (headers["Content-Location"] != null)
            {
                stringBuilder.Append("Content-Location").Append(": ");
                stringBuilder.Append(headers["Content-Location"]).Append("\r\n");
            }

            if (headers["Content-ID"] != null)
            {
                stringBuilder.Append("Content-ID").Append(": ");
                stringBuilder.Append(headers["Content-ID"]).Append("\r\n");
            }

            stringBuilder.Append("\r\n");

            writer.Write(stringBuilder.ToString());
        }