本文整理汇总了C#中MailAddressCollection类的典型用法代码示例。如果您正苦于以下问题:C# MailAddressCollection类的具体用法?C# MailAddressCollection怎么用?C# MailAddressCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MailAddressCollection类属于命名空间,在下文中一共展示了MailAddressCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMail
public static void SendMail(string FromName, string Subject, string Body, MailAddressCollection addresses)
{
System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage();
for (int i = 0; i < addresses.Count; i++) {
email.To.Add(addresses[i]);
}
email.From = new MailAddress(ConfigurationManager.AppSettings["FromEmail"], FromName);
email.Subject = Subject;
email.Body = Body;
email.IsBodyHtml = true;
email.Priority = MailPriority.Normal;
email.BodyEncoding = System.Text.Encoding.UTF8;
SmtpClient mailClient = new System.Net.Mail.SmtpClient();
mailClient.Timeout = 400000;
mailClient.EnableSsl = false;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential basicAuthenticationInfo =
new NetworkCredential("[email protected]", "147258");
mailClient.Host = "mail.dbhsoft.com";
mailClient.Credentials = basicAuthenticationInfo;
mailClient.Port = 587;
try {
mailClient.Send(email);
} catch (Exception) {
throw;
}
}
示例2: AddMailsToCollection
/// <summary>
/// Adds the mails to the address-collection.
/// </summary>
/// <param name="collection">The collection.</param>
/// <param name="addresses">The addresses.</param>
private void AddMailsToCollection(MailAddressCollection collection, IEnumerable<string> addresses)
{
foreach (string address in addresses)
{
collection.Add(new MailAddress(address));
}
}
示例3: Enviar
public static void Enviar(MailAddress to, String body, String subject, List<Attachment> attachments)
{
MailAddressCollection emails = new MailAddressCollection();
emails.Add(to);
MailAddress from = Util.Email.EmailEnvioPadrao;
Enviar(from, emails, body, subject, attachments);
}
示例4: SendEmail
public void SendEmail(MailAddress from, MailAddressCollection to, MailAddressCollection cc, MailAddressCollection bcc, string subj, string body)
{
MailMessage msg = new MailMessage();
foreach(MailAddress item in to)
{
msg.To.Add(item);
}
foreach (MailAddress item in cc)
{
msg.CC.Add(item);
}
foreach (MailAddress item in bcc)
{
msg.Bcc.Add(item);
}
msg.From = from;
msg.Sender = from;
Log.Info("Preparing message FROM " + from.DisplayName + " at address " + from.Address);
msg.Subject = subj;
msg.Body = body;
Log.Info("Sending email message...");
try
{
tseClient.Send(msg);
}
catch (Exception)
{
throw;
}
}
示例5: SendAnEmail
public void SendAnEmail()
{
bool _success = false;
try
{
MailMessage _message = new MailMessage();
SmtpClient _smptClient = new SmtpClient();
_message.Subject = _emailSubject;
_message.Body = _emailBody;
MailAddress _mailFrom = new MailAddress(_emailFrom,_emailFromFriendlyName);
MailAddressCollection _mailTo = new MailAddressCollection();
_mailTo.Add(_emailTo);
_message.From = _mailFrom;
_message.To.Add(new MailAddress(_emailTo,_emailToFriendlyName));
System.Net.NetworkCredential _crens = new System.Net.NetworkCredential(
_smtpHostUserName,_smtpHostPassword);
_smptClient.Host = _smtpHost;
_smptClient.Credentials = _crens;
_smptClient.Send(_message);
}
catch (Exception er)
{
string s1 = er.Message;
}
}
示例6: Send
public static void Send(MailAddress from, MailAddress replyTo, MailAddress to, string subject, string body)
{
MailAddressCollection toList = new MailAddressCollection();
toList.Add(to);
Send(from, replyTo, toList, subject, body);
}
示例7: SendAnEmail
public void SendAnEmail()
{
try
{
MailMessage _message = new MailMessage();
SmtpClient _smptClient = new SmtpClient();
_message.Subject = _emailSubject;
_message.Body = _emailBody;
MailAddress _mailFrom = new MailAddress(_emailFrom,_emailFromFriendlyName);
MailAddressCollection _mailTo = new MailAddressCollection();
_mailTo.Add(_emailTo);
_message.From = _mailFrom;
_message.To.Add(new MailAddress(_emailTo,_emailToFriendlyName));
System.Net.NetworkCredential _crens = new System.Net.NetworkCredential(
_smtpHostUserName,_smtpHostPassword);
_smptClient.Host = _smtpHost;
_smptClient.Credentials = _crens;
_smptClient.Send(_message);
}
catch (Exception er)
{
Log("C:\\temp\\", "Error.log", er.ToString());
}
}
示例8: Main
static void Main(string[] args)
{
// Create attendees of the meeting
MailAddressCollection attendees = new MailAddressCollection();
attendees.Add("[email protected]");
attendees.Add("[email protected]");
// Set up appointment
Appointment app = new Appointment(
"Location", // location of meeting
DateTime.Now, // start date
DateTime.Now.AddHours(1), // end date
new MailAddress("[email protected]"), // organizer
attendees); // attendees
// Set up message that needs to be sent
MailMessage msg = new MailMessage();
msg.From = "[email protected]";
msg.To = "[email protected]";
msg.Subject = "appointment request";
msg.Body = "you are invited";
// Add meeting request to the message
msg.AddAlternateView(app.RequestApointment());
// Set up the SMTP client to send email with meeting request
SmtpClient client = new SmtpClient("host", 25, "user", "password");
client.Send(msg);
}
示例9: ParseAddressList
internal override MailAddress[] ParseAddressList(string list)
{
List<MailAddress> mails = new List<MailAddress>();
if (string.IsNullOrEmpty(list))
return mails.ToArray();
foreach (string part in SplitAddressList(list))
{
MailAddressCollection mcol = new MailAddressCollection();
try
{
// .NET won't accept address-lists ending with a ';' or a ',' character, see #68.
mcol.Add(part.TrimEnd(';', ','));
foreach (MailAddress m in mcol)
{
// We might still need to decode the display name if it is Q-encoded.
string displayName = Util.DecodeWords(m.DisplayName);
mails.Add(new MailAddress(m.Address, displayName));
}
}
catch
{
// We don't want this to throw any exceptions even if the entry is malformed.
}
}
return mails.ToArray();
}
示例10: Run
public static void Run()
{
// ExStart:GetMailTips
// Create instance of EWSClient class by giving credentials
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
Console.WriteLine("Connected to Exchange server...");
// Provide mail tips options
MailAddressCollection addrColl = new MailAddressCollection();
addrColl.Add(new MailAddress("[email protected]", true));
addrColl.Add(new MailAddress("[email protected]", true));
GetMailTipsOptions options = new GetMailTipsOptions("[email protected]", addrColl, MailTipsType.All);
// Get Mail Tips
MailTips[] tips = client.GetMailTips(options);
// Display information about each Mail Tip
foreach (MailTips tip in tips)
{
// Display Out of office message, if present
if (tip.OutOfOffice != null)
{
Console.WriteLine("Out of office: " + tip.OutOfOffice.ReplyBody.Message);
}
// Display the invalid email address in recipient, if present
if (tip.InvalidRecipient == true)
{
Console.WriteLine("The recipient address is invalid: " + tip.RecipientAddress);
}
}
// ExEnd:GetMailTips
}
示例11: Populate
private void Populate(MailAddressCollection dest, IEnumerable<string> source)
{
foreach (string mail in source)
{
dest.Add(FromString(mail));
}
}
示例12: ApplyMailAddressOverride
/// <summary>
/// Applies the override to a MailAddressCollection
/// </summary>
/// <param name="addresses">The addresses.</param>
/// <returns></returns>
protected MailAddressCollection ApplyMailAddressOverride(MailAddressCollection addresses)
{
if (clear)
{
addresses.Clear();
}
else
{
if (!string.IsNullOrEmpty(overrideString))
{
addresses.Clear();
addresses.Add(overrideString);
}
if (!string.IsNullOrEmpty(prependString))
{
var old = addresses.ToString();
addresses.Clear();
addresses.Add(prependString);
if(!string.IsNullOrWhiteSpace(old)) addresses.Add(old);
}
if (!string.IsNullOrEmpty(appendString))
{
addresses.Add(appendString);
}
}
return addresses;
}
示例13: SendEmail
/// <summary>
/// Send a plain text email with the specified properties. The email will appear to come from the name and email specified in the
/// EmailFromName and EmailFromAddress configuration settings. If the emailRecipient parameter is not specified, the email
/// is sent to the address configured in the emailToAddress setting in the configuration file. The e-mail is sent on a
/// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is
/// recorded in the error log). If it is important to know if the e-mail was successfully sent, use the overload of this
/// method that specifies a sendOnBackgroundThread parameter.
/// </summary>
/// <param name="emailRecipient">The recipient of the email.</param>
/// <param name="subject">The text to appear in the subject of the email.</param>
/// <param name="body">The body of the email. If the body is HTML, specify true for the isBodyHtml parameter.</param>
public static void SendEmail(MailAddress emailRecipient, string subject, string body)
{
MailAddressCollection mailAddresses = new MailAddressCollection();
mailAddresses.Add(emailRecipient);
SendEmail(mailAddresses, subject, body, false, true);
}
示例14: CreateMailMessage
private void CreateMailMessage(DeliveryInfo deliveryInfo, MailMessage message)
{
var recipients = deliveryInfo.To;
if (string.IsNullOrEmpty(recipients)) throw new ArgumentNullException(recipients);
var addressCollection = new MailAddressCollection();
if (!MailSettings.UseEmailTestMode) addressCollection.Add(recipients);
else addressCollection.Add(MailSettings.TestEmailAddress);
foreach (var address in addressCollection)
{
message.To.Add(EmailHelper.FixMailAddressDisplayName(address, MailSettings.EmailHeaderEncoding));
}
message.From = EmailHelper.FixMailAddressDisplayName(new MailAddress(deliveryInfo.From), MailSettings.EmailHeaderEncoding);
message.BodyEncoding = Encoding.GetEncoding(MailSettings.EmailBodyEncoding);
message.SubjectEncoding = Encoding.GetEncoding(MailSettings.EmailSubjectEncoding);
message.HeadersEncoding = Encoding.GetEncoding(MailSettings.EmailHeaderEncoding);
message.Body = deliveryInfo.Body;
message.IsBodyHtml = deliveryInfo.IsBodyHtml;
message.Subject = deliveryInfo.Subject;
if (!string.IsNullOrEmpty(deliveryInfo.ReplyTo))
{
var replyToCollection = new MailAddressCollection { deliveryInfo.ReplyTo };
foreach (var address in replyToCollection)
{
message.ReplyToList.Add(EmailHelper.FixMailAddressDisplayName(address, MailSettings.EmailHeaderEncoding));
}
}
}
示例15: CopyToMailAddressCollection
public void CopyToMailAddressCollection(Rebex.Mime.Headers.MailAddressCollection rmac, MailAddressCollection mac)
{
foreach (Rebex.Mime.Headers.MailAddress rma in rmac)
{
mac.Add(ToMailAddress(rma));
}
}