📄 newmessage.cs
字号:
}
bool attachments = false;
if ( this._message_mode.Equals(anmar.SharpWebMail.UI.MessageMode.forward) )
attachments = (bool)Application["sharpwebmail/send/message/forwardattachments"];
message = new anmar.SharpMimeTools.SharpMessage(ms, attachments, html_content, path);
}
if ( this._message_mode.Equals(anmar.SharpWebMail.UI.MessageMode.reply) ) {
// From name if present on original message's To header
// and we don't have it already
if ( Session["DisplayName"]==null ) {
foreach ( anmar.SharpMimeTools.SharpMimeAddress address in (System.Collections.IEnumerable) details[8] ) {
if ( address["address"]!=null && address["address"].Equals( User.Identity.Name )
&& address["name"].Length>0 && !address["address"].Equals(address["name"]) ) {
this.fromname.Value = address["name"];
break;
}
}
}
// To addresses
foreach ( anmar.SharpMimeTools.SharpMimeAddress address in (System.Collections.IEnumerable) details[9] ) {
if ( address["address"]!=null && !address["address"].Equals( User.Identity.Name ) ) {
if ( this.toemail.Value.Length >0 )
this.toemail.Value += ", ";
this.toemail.Value += address["address"];
}
}
} else if ( this._message_mode.Equals(anmar.SharpWebMail.UI.MessageMode.forward) ) {
// If the original message has attachments, preserve them
if ( message!=null && message.Attachments!=null && message.Attachments.Count>0 ) {
this.bindAttachments();
foreach ( anmar.SharpMimeTools.SharpAttachment attachment in message.Attachments ) {
if ( attachment.SavedFile==null )
continue;
this.AttachmentSelect(System.IO.Path.Combine(attachment.SavedFile.Directory.Name, attachment.SavedFile.Name));
}
this.Attach_Click(this, null);
}
}
// Preserve the original body and some properties
if ( message!=null ) {
System.Text.StringBuilder sb_body = new System.Text.StringBuilder();
System.String line_end = null;
if ( html_content )
line_end = "<br />\r\n";
else
line_end = "\r\n";
sb_body.Append(this.SharpUI.LocalizedRS.GetString(System.String.Concat(this._message_mode, "PrefixBody")));
sb_body.Append(line_end);
sb_body.Append(this.SharpUI.LocalizedRS.GetString("newMessageWindowFromNameLabel"));
sb_body.Append(" ");
sb_body.Append(message.From);
sb_body.Append(" [mailto:");
sb_body.Append(message.FromAddress);
sb_body.Append("]");
sb_body.Append(line_end);
sb_body.Append(this.SharpUI.LocalizedRS.GetString("newMessageWindowDateLabel"));
sb_body.Append(" ");
sb_body.Append(message.Date.ToString());
sb_body.Append(line_end);
sb_body.Append(this.SharpUI.LocalizedRS.GetString("newMessageWindowToEmailLabel"));
sb_body.Append(" ");
if ( html_content )
sb_body.Append(System.Web.HttpUtility.HtmlEncode(message.To.ToString()));
else
sb_body.Append(message.To);
sb_body.Append(line_end);
sb_body.Append(this.SharpUI.LocalizedRS.GetString("newMessageWindowSubjectLabel"));
sb_body.Append(" ");
sb_body.Append(message.Subject);
sb_body.Append(line_end);
sb_body.Append(line_end);
if ( !message.HasHtmlBody && html_content )
sb_body.Append("<pre>");
sb_body.Append(message.Body);
if ( !message.HasHtmlBody && html_content )
sb_body.Append("</pre>");
if ( this._message_mode.Equals(anmar.SharpWebMail.UI.MessageMode.reply) ) {
if ( html_content ) {
sb_body.Insert(0, System.String.Concat("<blockquote style=\"", Application["sharpwebmail/send/message/replyquotestyle"] ,"\">"));
sb_body.Append("</blockquote>");
} else {
sb_body.Insert(0, Application["sharpwebmail/send/message/replyquotechar"].ToString());
sb_body.Replace("\n", System.String.Concat("\n", Application["sharpwebmail/send/message/replyquotechar"]));
}
}
sb_body.Insert(0, line_end);
sb_body.Insert(0, " ");
this.FCKEditor.Value = sb_body.ToString();
}
}
details = null;
}
} else if ( !this.IsPostBack ) {
System.String to = Page.Request.QueryString["to"];
if ( to!=null && to.Length>0 ) {
this.toemail.Value = to;
}
}
if ( this.fromname.Value.Length>0 || this.IsPostBack )
Session["DisplayName"] = this.fromname.Value;
if ( this.fromname.Value.Length==0 && Session["DisplayName"]!=null )
this.fromname.Value = Session["DisplayName"].ToString();
if ( this.fromemail.Value.Length>0 || this.IsPostBack )
Session["DisplayEmail"] = this.fromemail.Value;
}
private void ProcessMessageAttachments (System.Object message) {
// Attachments
if ( this.newMessageWindowAttachmentsAddedList.Items.Count>0 ) {
anmar.SharpWebMail.CTNInbox inbox = (anmar.SharpWebMail.CTNInbox)Session["inbox"];
System.String Value="";
foreach ( System.Web.UI.WebControls.ListItem item in this.newMessageWindowAttachmentsList.Items ) {
if ( item.Selected ) {
if ( log.IsDebugEnabled ) log.Debug ( System.String.Format ("Attaching {0} {1}", item.Text, item.Value) );
if ( !item.Value.StartsWith ( Session.SessionID ) ) {
Value = item.Value.Substring ( 0 , item.Value.IndexOf ( System.IO.Path.DirectorySeparatorChar ));
System.Object[] details = inbox[ Value ];
if ( details == null ) {
Value=null;
}
details = null;
}
if ( Value!=null ) {
System.String attachment = this.getfilename (Session["sharpwebmail/send/message/temppath"], Value, item.Text.Substring(0, item.Text.LastIndexOf(" (")));
if ( attachment==null )
attachment = this.getfilename (Session["sharpwebmail/read/message/temppath"], Value, item.Text.Substring(0, item.Text.LastIndexOf(" (")));
if ( attachment!=null ) {
if ( message is System.Web.Mail.MailMessage )
((System.Web.Mail.MailMessage)message).Attachments.Add(new System.Web.Mail.MailAttachment(attachment));
else if ( message is DotNetOpenMail.EmailMessage )
((DotNetOpenMail.EmailMessage)message).AddMixedAttachment(new DotNetOpenMail.FileAttachment(new System.IO.FileInfo(attachment)));
else if ( message is OpenSmtp.Mail.MailMessage )
((OpenSmtp.Mail.MailMessage)message).AddAttachment(attachment);
if ( log.IsDebugEnabled ) log.Debug ( System.String.Format ("Attached {0}", attachment) );
}
}
}
}
}
}
/// <summary>
///
/// </summary>
private System.String SendMail ( anmar.SharpWebMail.EmailServerInfo server ) {
System.String message = null;
System.Web.Mail.SmtpMail.SmtpServer = server.Host;
System.Web.Mail.MailMessage mailMessage = new System.Web.Mail.MailMessage();
mailMessage.To = this.toemail.Value;
mailMessage.From = System.String.Format("{0} <{1}>", this.fromname.Value, this.GetFromAddress());
mailMessage.Subject = this.subject.Value.Trim();
System.String format = Request.Form["format"];
if ( format!=null && format.Equals("html") ) {
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Html;
mailMessage.Body = bodyStart + FCKEditor.Value + bodyEnd;
} else {
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text;
mailMessage.Body = FCKEditor.Value;
}
if ( this._headers != null ) {
// RFC 2822 3.6.4. Identification fields
if ( this._headers["Message-ID"]!=null ) {
mailMessage.Headers["In-Reply-To"] = this._headers["Message-ID"];
mailMessage.Headers["References"] = this._headers["Message-ID"];
}
if ( this._headers["References"]!=null ) {
mailMessage.Headers["References"] = System.String.Concat (this._headers["References"], " ", mailMessage.Headers["References"]).Trim();
} else if ( this._headers["In-Reply-To"]!=null && this._headers["In-Reply-To"].IndexOf('>')==this._headers["In-Reply-To"].LastIndexOf('>') ) {
mailMessage.Headers["References"] = System.String.Concat (this._headers["In-Reply-To"], " ", mailMessage.Headers["References"]).Trim();
}
}
mailMessage.Headers["X-Mailer"] = System.String.Format ("{0} {1}", Application["product"], Application["version"]);
this.ProcessMessageAttachments(mailMessage);
try {
if ( log.IsDebugEnabled) log.Error ( "Sending message" );
System.Web.Mail.SmtpMail.Send(mailMessage);
if ( log.IsDebugEnabled) log.Error ( "Message sent" );
} catch (System.Exception e) {
message = e.Message;
#if DEBUG && !MONO
message += ". <br>InnerException: " + e.InnerException.Message;
#endif
if ( log.IsErrorEnabled ) log.Error ( "Error sending message", e );
if ( log.IsErrorEnabled ) log.Error ( "Error sending message (InnerException)", e.InnerException );
}
mailMessage = null;
return message;
}
private System.String SendMailDotNetOpenMail ( anmar.SharpWebMail.EmailServerInfo server ) {
System.String message = null;
DotNetOpenMail.EmailMessage mailMessage = new DotNetOpenMail.EmailMessage();
mailMessage.FromAddress = new DotNetOpenMail.EmailAddress(this.GetFromAddress(), this.fromname.Value);
System.String[] tokens = anmar.SharpMimeTools.ABNF.address_regex.Split(this.toemail.Value);
foreach ( System.String token in tokens ) {
if ( anmar.SharpMimeTools.ABNF.address_regex.IsMatch(token ) )
mailMessage.AddToAddress (new DotNetOpenMail.EmailAddress(token.Trim()));
}
mailMessage.Subject = this.subject.Value.Trim();
System.String format = Request.Form["format"];
if ( format!=null && format.Equals("html") ) {
mailMessage.HtmlPart = new DotNetOpenMail.HtmlAttachment(bodyStart + FCKEditor.Value + bodyEnd);
} else {
mailMessage.TextPart = new DotNetOpenMail.TextAttachment(FCKEditor.Value);
}
if ( this._headers != null ) {
// RFC 2822 3.6.4. Identification fields
if ( this._headers["Message-ID"]!=null ) {
mailMessage.AddCustomHeader("In-Reply-To", this._headers["Message-ID"]);
mailMessage.AddCustomHeader("References", this._headers["Message-ID"]);
}
if ( this._headers["References"]!=null ) {
mailMessage.AddCustomHeader("References", System.String.Concat (this._headers["References"], " ", this._headers["Message-ID"]).Trim());
} else if ( this._headers["In-Reply-To"]!=null && this._headers["In-Reply-To"].IndexOf('>')==this._headers["In-Reply-To"].LastIndexOf('>') ) {
mailMessage.AddCustomHeader("References", System.String.Concat (this._headers["In-Reply-To"], " ", this._headers["Message-ID"]).Trim());
}
}
mailMessage.XMailer = System.String.Concat (Application["product"], " ", Application["version"]);
this.ProcessMessageAttachments(mailMessage);
try {
if ( log.IsDebugEnabled) log.Error ( "Sending message" );
DotNetOpenMail.SmtpServer SmtpMail = new DotNetOpenMail.SmtpServer(server.Host, server.Port);
if ( server.Protocol.Equals(anmar.SharpWebMail.ServerProtocol.SmtpAuth) ) {
anmar.SharpWebMail.IEmailClient client = (anmar.SharpWebMail.IEmailClient)Session["client"];
SmtpMail.SmtpAuthToken = new DotNetOpenMail.SmtpAuth.SmtpAuthToken(client.UserName, client.Password);
}
mailMessage.Send(SmtpMail);
SmtpMail=null;
if ( log.IsDebugEnabled) log.Error ( "Message sent" );
} catch (System.Exception e) {
message = e.Message;
if ( log.IsErrorEnabled ) log.Error ( "Error sending message", e );
}
mailMessage = null;
return message;
}
private System.String SendMailOpenSmtp ( anmar.SharpWebMail.EmailServerInfo server ) {
System.String message = null;
OpenSmtp.Mail.MailMessage mailMessage = new OpenSmtp.Mail.MailMessage();
mailMessage.From = new OpenSmtp.Mail.EmailAddress(this.GetFromAddress(), this.fromname.Value);
System.String[] tokens = anmar.SharpMimeTools.ABNF.address_regex.Split(this.toemail.Value);
foreach ( System.String token in tokens ) {
if ( anmar.SharpMimeTools.ABNF.address_regex.IsMatch(token ) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -