本文整理汇总了C#中MailPriority类的典型用法代码示例。如果您正苦于以下问题:C# MailPriority类的具体用法?C# MailPriority怎么用?C# MailPriority使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MailPriority类属于命名空间,在下文中一共展示了MailPriority类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmailTemplate
public EmailTemplate(XmlNode rootNode)
{
XmlNode namedItem = rootNode.Attributes.GetNamedItem("priority");
MailPriority mailPriority;
if (namedItem != null && System.Enum.TryParse<MailPriority>(namedItem.InnerText, out mailPriority))
{
this.priority = mailPriority;
}
namedItem = rootNode.Attributes.GetNamedItem("templateName");
if (namedItem != null)
{
this.templateName = namedItem.InnerText;
}
XmlNode xmlNode = rootNode.SelectSingleNode("subject");
if (xmlNode != null)
{
this.subject = xmlNode.InnerText;
}
XmlNode xmlNode2 = rootNode.SelectSingleNode("from");
if (xmlNode2 != null)
{
this.From = xmlNode2.InnerText;
}
XmlNode xmlNode3 = rootNode.SelectSingleNode("body");
if (xmlNode3 != null)
{
namedItem = xmlNode3.Attributes.GetNamedItem("url");
if (namedItem != null)
{
this.BodyUrl = namedItem.InnerText;
return;
}
this.Body = xmlNode3.InnerXml;
}
}
示例2: SendEmail
public bool SendEmail(string subject, IList<string> userList, IList<string> ccList, string body, MailPriority priority = MailPriority.Normal)
{
var mail = new MailMessage
{
From = fromAddress,
Subject = subject,
Body = body,
BodyEncoding = Encoding.UTF8,
IsBodyHtml = true,
Priority = priority
};
foreach (var user in userList)
mail.To.Add(user);
foreach (var cc in ccList)
mail.CC.Add(cc);
var client = new SmtpClient
{
Host = host,
UseDefaultCredentials = false,
Credentials = new System.Net.NetworkCredential(userName, password),
DeliveryMethod = SmtpDeliveryMethod.Network
};
try
{
client.Send(mail);
return true;
}
catch
{
return false;
}
}
示例3: SendMailMessage
//function to send email. Returns true if successful, returns false if unsuccessful
public static bool SendMailMessage(string from, string recipient, string bcc, string cc, string subject, string body, bool isHTML, MailPriority priority)
{
try
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress(from); //set from address
string[] arrRecipients = recipient.Split(';'); //add recipients to "TO" field
foreach (object x in arrRecipients) { msg.To.Add(new MailAddress(x.ToString())); }
if (bcc != "" && bcc != null) { msg.Bcc.Add(new MailAddress(bcc)); } //set bcc field
if (cc != "" && cc != null) { msg.CC.Add(new MailAddress(cc)); } //set cc field
msg.Subject = subject; //set subject field
if (isHTML == false) { msg.IsBodyHtml = false; } //set HTML option depending on param
else { msg.IsBodyHtml = true; }
msg.Body = body; //set body
msg.Priority = priority; //set message priority
SmtpClient client = new SmtpClient(); //new SMTP client - settings in web.config
client.Send(msg); //send message
}
catch {return false; }
return true;
}
示例4: SendBulkEmail
public SendBulkEmail( ArrayList recipients, string priority, string format, string portalAlias )
{
this.Recipients = recipients;
switch( priority )
{
case "1":
this.Priority = MailPriority.High;
break;
case "2":
this.Priority = MailPriority.Normal;
break;
case "3":
this.Priority = MailPriority.Low;
break;
}
if( format == "BASIC" )
{
this.BodyFormat = MailFormat.Text;
}
else
{
this.BodyFormat = MailFormat.Html;
// Add Base Href for any images inserted in to the email.
this.Body = "<Base Href='" + portalAlias + "'>";
}
}
示例5: SendEmail
/// <summary>
/// 结合配置文件改的
/// </summary>
/// <param name="mail"></param>
public static bool SendEmail(string from, string displayName, string to0, string subject, string body, string encoding, MailPriority prioity)
{
if (string.IsNullOrEmpty(displayName))
displayName = from;
MailAddress _from = new MailAddress(from, displayName);
MailAddress _to = new MailAddress(to0);
MailMessage mail = new MailMessage(_from, _to);
mail.Subject = subject;
mail.Body = body;
mail.BodyEncoding = System.Text.Encoding.Default;
if (!string.IsNullOrEmpty(encoding))
{
mail.BodyEncoding = System.Text.Encoding.GetEncoding(encoding);
}
mail.IsBodyHtml = true;
mail.Priority = prioity;
Configs.Config cfg = new Configs.Config();
// Override To
if (!string.IsNullOrEmpty(cfg.Email.MailTo_Override))
{
var tos = cfg.Email.MailTo_Override.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
mail.To.Clear();
foreach (var to in tos)
{
mail.To.Add(to);
}
}
return SendEmail(mail);
}
示例6: Delivery
/// <summary>
/// Automatically sends email to Report Error Email. CC and BCC are allowed.
/// </summary>
/// <param name="subject">Email Subject.</param>
/// <param name="message">Email Message. It can be HTML.</param>
/// <param name="priority"> Mail Priority Normal | Low | High</param>
/// <param name="isHtml">Automatically set as TRUE, change to False for a non html message.</param>
/// <param name="CC"></param>
/// <param name="BCC"></param>
/// <returns></returns>
public static bool Delivery(string subject, string message, MailPriority priority, bool isHtml = true, string[] CC = null, string[] BCC = null)
{
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["smtpServer"]);
try
{
mail.To.Add(ConfigurationManager.AppSettings["ReportErrorsEmail"]);
mail.From = new MailAddress(ConfigurationManager.AppSettings["NoReplyEmail"]);
mail.Priority = priority;
mail.IsBodyHtml = isHtml;
mail.Subject = subject;
mail.Body = message;
if (CC != null)
foreach (var item in CC)
mail.CC.Add(item);
if (BCC != null)
foreach (var item in BCC)
mail.Bcc.Add(item);
smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["smtpUsrEmail"], ConfigurationManager.AppSettings["smtpPwd"]);
// Use port as necessary.
smtp.Port = 587;
smtp.Send(mail);
return true;
}
catch (Exception ex)
{
return false;
}
}
示例7: InviaEmailAsync
/// <summary>
///
/// </summary>
/// <param name="smtpClient"></param>
/// <param name="MailFrom_Address"></param>
/// <param name="MailTo_Address"></param>
/// <param name="Subject"></param>
/// <param name="Body"></param>
/// <param name="IsBodyEncoded"></param>
/// <param name="IsBodyHtml"></param>
/// <param name="Priority"></param>
/// <param name="Attachments">DisposableList<Attachment></param>
/// <returns></returns>
public static async Task InviaEmailAsync(SmtpClient smtpClient,
MailAddress MailFrom_Address, string MailsTo,
string Subject, string Body,
bool IsBodyEncoded = false,
bool IsBodyHtml = false,
MailPriority Priority = MailPriority.Normal,
List<Attachment> Attachments = null)
{
using (MailMessage mailMsg = new MailMessage())
{
mailMsg.From = MailFrom_Address;
mailMsg.To.Add(MailsTo);
mailMsg.Subject = Subject;
string body = Body;
if (IsBodyEncoded)
body = System.Net.WebUtility.HtmlDecode(body);
mailMsg.Body = body;
mailMsg.IsBodyHtml = IsBodyHtml;
mailMsg.Priority = Priority;
//allegati
if (Attachments != null && Attachments.Count > 0)
foreach (var attach in Attachments)
mailMsg.Attachments.Add(attach);
await smtpClient.SendMailAsync(mailMsg).ConfigureAwait(false);
}
}
示例8: Message
public Message(string subject, string recipientAddress,
string htmlBody, string plainTextBody,
string senderAddress = "", string senderName = "",
MailPriority priority = MailPriority.Normal,
string copyAddress = "", string blindCopyAddress = "")
{
if(string.IsNullOrEmpty(subject))
throw new ArgumentOutOfRangeException("subject", "The 'subject' parameter can not be null or empty");
if(string.IsNullOrEmpty(recipientAddress))
throw new ArgumentOutOfRangeException("recipientAddress", "The 'recipientAddress' parameter can not be null or empty");
if(string.IsNullOrEmpty(htmlBody))
throw new ArgumentOutOfRangeException("htmlBody", "The 'htmlBody' parameter can not be null or empty");
if(string.IsNullOrEmpty(plainTextBody))
throw new ArgumentOutOfRangeException("plainTextBody", "The 'plainTextBody' parameter can not be null or empty");
this._Subject = subject;
this._RecipientAddress = recipientAddress;
if(senderAddress != "") this._Sender = new MailAddress(senderAddress, senderName);
this._HtmlBody = htmlBody;
this._PlainTextBody = plainTextBody;
this._Priority = priority;
this._CopyAddress = copyAddress;
this._BlindCopyAddress = blindCopyAddress;
}
示例9: SetBasicInfos
private static MailMessage SetBasicInfos(string MessageFrom, string MessageTo, string MessageCc, string MessageBcc, string MessageSubject, MailPriority MessagePriority, string MessageText)
{
char[] delim = { ',', ';', ' ', ':', '\\', '|' };
StringSplitOptions opt = StringSplitOptions.RemoveEmptyEntries;
MailMessage myMail = new MailMessage();
myMail.From = new MailAddress(MessageFrom);
myMail.To.AddList(MessageTo.Split(delim, opt).Encapsulate<string, MailAddress>());
if (!String.IsNullOrEmpty(MessageCc))
myMail.CC.AddList<MailAddress>(
MessageCc.Split(delim, opt)
.Encapsulate<string, MailAddress>()
);
if (!String.IsNullOrEmpty(MessageBcc))
myMail.Bcc.AddList<MailAddress>(
MessageCc.Split(delim, opt)
.Encapsulate<string, MailAddress>()
);
myMail.Subject = MessageSubject;
myMail.Priority = MessagePriority;
myMail.BodyEncoding = Encoding.UTF8;
myMail.Body = MessageText;
return myMail;
}
示例10: SendTemplateMail
/// <summary>
/// Sends the template mail.
/// </summary>
/// <param name="mailSettings">STMP email settings</param>
/// <param name="fromAddress">From address.</param>
/// <param name="fromDisplayName">From display name.</param>
/// <param name="toAddress">To address.</param>
/// <param name="toName">To display name.</param>
/// <param name="ccAddressesCSV">Optional CC addresses (CSV).</param>
/// <param name="bccAddressesCSV">Optional BCC addresses CSV.</param>
/// <param name="subject">The subject.</param>
/// <param name="templateFilePath">The template file path.</param>
/// <param name="replacements">The replacements.</param>
/// <param name="appRootFolder">'/' if site is running in the base folder, or '/foldername/' if site is running in a sub-folder.</param>
/// <param name="templateVirtualFolder">The template virtual folder.</param>
/// <param name="wrapperTemplateFilePath">Optional wrapper template file path.</param>
/// <param name="isBodyHtml">Set to true if the body of the email is HTML; false otherwise.</param>
public static void SendTemplateMail(MailSettings mailSettings, string toAddress, string toName,
string ccAddressesCSV, string bccAddressesCSV, string subject, string templateFilePath,
ListDictionary replacements, string templateVirtualFolder, string appRootFolder, string wrapperTemplateFilePath = null, bool isBodyHtml = true, MailPriority priority = MailPriority.Normal,
string attachmentDosPaths = null)
{
if (File.Exists(templateFilePath))
{
StringBuilder messageText = null;
string templateText = null;
if (File.Exists(templateFilePath))
{
templateText = File.ReadAllText(templateFilePath);
}
else
{
throw new Exception("Cannot find template " + templateFilePath);
}
if (!string.IsNullOrEmpty(wrapperTemplateFilePath) && File.Exists(wrapperTemplateFilePath))
{
string str = File.ReadAllText(wrapperTemplateFilePath).Replace("@@WrapperContents", templateText);
messageText = new StringBuilder(str);
}
else
{
messageText = new StringBuilder(templateText);
}
// Add some mandatory fields to the replacements
if (replacements == null)
{
// Ensure not null.
replacements = new ListDictionary();
}
replacements.Add("@@HttpRoot", string.Format("http://{0}/", mailSettings.Host));
replacements.Add("@@TemplateFolder", string.Format("http://{0}{1}{2}", mailSettings.Host, appRootFolder, templateVirtualFolder.Trim("~/".ToCharArray())));
SendMail(
mailSettings,
toAddress,
toName,
ccAddressesCSV,
bccAddressesCSV,
subject,
messageText.ToString(),
true,
attachmentDosPaths,
priority,
replacements);
}
else
{
//Every1.Core.Web.Utils.TraceWarn("SendTemplateMail", "templateFilePath " + templateFilePath + " does not exist");
}
}
示例11: Email
/// <summary>
/// Sends and email
/// </summary>
/// <param name="to">Message to address</param>
/// <param name="body">Text of message to send</param>
/// <param name="subject">Subject line of message</param>
/// <param name="fromAddress">Message from address</param>
/// <param name="fromDisplay">Display name for "message from address"</param>
/// <param name="credentialUser">User whose credentials are used for message send</param>
/// <param name="credentialPassword">User password used for message send</param>
/// <param name="attachments">Optional attachments for message</param>
public static void Email(string mailServerAddress,
string toAddress,
string body,
string subject,
string fromAddress,
string fromDisplay,
string credentialUser,
string credentialPassword,
MailAttachment[] attachments,
string linkConfirm = null,
string passPlainText = null,
MailType mailType = MailType.Normal,
MailPriority mailpriority = MailPriority.Normal)
{
string host = mailServerAddress;
body = UpgradeEmailFormat(body, linkConfirm, passPlainText, mailType);
try
{
MailMessage mail = new MailMessage() { Body = body, IsBodyHtml = true };
string[] toArray = toAddress.Split(';');
foreach (string to in toArray)
{
mail.To.Add(new MailAddress(to.Trim()));
}
mail.From = new MailAddress(fromAddress, fromDisplay, Encoding.UTF8);
mail.Subject = subject;
mail.SubjectEncoding = Encoding.UTF8;
mail.Priority = mailpriority;
using (SmtpClient smtp = new SmtpClient())
{
// This is necessary for gmail
//smtp.EnableSsl = true;
//smtp.Credentials = new System.Net.NetworkCredential(credentialUser, credentialPassword);
smtp.Host = host;
smtp.Send(mail);
}
}
catch
{
StringBuilder sb = new StringBuilder(1024);
sb.Append("\\nTo:" + toAddress);
sb.Append("\\nbody:" + body);
sb.Append("\\nsubject:" + subject);
sb.Append("\\nfromAddress:" + fromAddress);
sb.Append("\\nfromDisplay:" + fromDisplay);
sb.Append("\\ncredentialUser:" + credentialUser);
sb.Append("\\ncredentialPasswordto:" + credentialPassword);
sb.Append("\\nHosting:" + host);
Debug.Print(sb.ToString());
}
}
示例12: SendEmail
public Boolean SendEmail(String toAddress, String addresseName, String from, String senderName, String subject, String msgBody, MailPriority msgPriority)
{
try
{
return SendEmail(toAddress, addresseName, String.Empty, String.Empty, from, senderName, subject, msgBody, true, msgPriority);
}
catch
{
return false;
}
}
示例13: SendEmailByCredential
public static bool SendEmailByCredential(string host, MailPriority priority, string user_name, string password, string[] mailto, string[] cc, string[] bcc, string subject, string body, bool is_body_html, string[] attachments, bool enableSSL, System.Collections.Specialized.NameValueCollection messageHeaders, string reply_to)
{
SmtpClient mail = new SmtpClient();
mail.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.Host = host;// "smtp.163.com";
mail.UseDefaultCredentials = false;
mail.Credentials = new System.Net.NetworkCredential(user_name, password);
mail.EnableSsl = enableSSL;
MailMessage message = new MailMessage();
if (messageHeaders != null && messageHeaders.Count > 0)
{
message.Headers.Add(messageHeaders);
}
message.From = new MailAddress(user_name + "@" + host.Substring(host.IndexOf(".") + 1));
if (mailto != null)
{
foreach (string s in mailto)
{
if (!string.IsNullOrEmpty(s))
message.To.Add(s);
}
}
if (cc != null)
{
foreach (string s in cc)
{
if (!string.IsNullOrEmpty(s))
message.CC.Add(s);
}
}
if (bcc != null)
{
foreach (string s in bcc)
{
if (!string.IsNullOrEmpty(s))
message.Bcc.Add(s);
}
}
if (!string.IsNullOrEmpty(reply_to)) message.ReplyTo = new MailAddress(reply_to);
message.Subject = subject;
message.Body = body;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = is_body_html;
message.Priority = priority;
if (attachments != null)
{
foreach (string s in attachments)
{
message.Attachments.Add(new Attachment(s));
}
}
mail.Send(message);
return true;
}
示例14: SendEmail
public void SendEmail(string subject, string body, string mailTo, string replayTo, MailPriority mailPriority)
{
//SendMailExchange(mailTo, subject, body, replayTo);
string SMTPEmailHost = systemMgr.GetEntityPreferenceValue(Entity.SYS.EntityPreference.CodeEnum.SMTPEmailHost);
string SMTPEmailPasswd = systemMgr.GetEntityPreferenceValue(Entity.SYS.EntityPreference.CodeEnum.SMTPEmailPasswd);
string emailFrom = systemMgr.GetEntityPreferenceValue(Entity.SYS.EntityPreference.CodeEnum.SMTPEmailAddr);
SMTPHelper.SendSMTPEMail(subject, body, emailFrom, mailTo, SMTPEmailHost, SMTPEmailPasswd, (!string.IsNullOrWhiteSpace(replayTo) ? replayTo : emailFrom), mailPriority);
}
示例15: Send
public static async Task Send(string to, string body, string subject, bool? isHtml = null, MailPriority priority = MailPriority.Normal)
{
MailMessage email = new MailMessage(new MailAddress(ConfigurationManager.AppSettings["EmailFrom"]), new MailAddress(to));
email.Subject = subject;
email.Body = body;
email.BodyEncoding = System.Text.Encoding.Default;
email.Priority = priority;
email.IsBodyHtml = (isHtml.HasValue ? isHtml.Value : true);
await smtpClient.SendMailAsync(email);
}