本文整理汇总了C#中EmailMessage类的典型用法代码示例。如果您正苦于以下问题:C# EmailMessage类的具体用法?C# EmailMessage怎么用?C# EmailMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EmailMessage类属于命名空间,在下文中一共展示了EmailMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendEmail
public void SendEmail(EmailMessage message, string account)
{
var fromAddress = new MailAddress(message.From);
var toAddress = new MailAddress(message.To);
var mailMessage = new MailMessage(fromAddress, toAddress);
mailMessage.Subject = message.Subject;
if (message.Bcc != null)
{
mailMessage.Bcc.Add(new MailAddress(message.Bcc));
}
mailMessage.Body = message.Message;
mailMessage.IsBodyHtml = message.IsHtml;
var networkCredentials = _credentials.GetCredentialsForAccount(account);
if (networkCredentials == null)
{
throw new Exception(String.Format(
"No credentials has been set for account: {0}. Please set up corresponding record in database", account
));
}
var client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = networkCredentials;
client.Host = "mail.trackyt.net";
client.Port = 587;
client.EnableSsl = false;
client.Send(mailMessage);
}
示例2: SendEmail
private static async Task SendEmail()
{
var emailMessage = new EmailMessage();
emailMessage.To.Add(new EmailRecipient("[email protected]"));
emailMessage.Subject = "Toastmaster Tools Feedback";
await EmailManager.ShowComposeNewEmailAsync(emailMessage);
}
示例3: SendEmail
public bool SendEmail(EmailMessage message, bool sendTranslated = false)
{
if (message.IsSent)
return false;
MailMessage eMessage = new MailMessage();
eMessage.To.Add(message.To);
eMessage.From = new MailAddress(message.From);
eMessage.Subject = message.Subject;
if (sendTranslated)
eMessage.Body = message.TranslatedBody;
else
eMessage.Body = message.Body;
eMessage.IsBodyHtml = true;
try
{
_smtpClient.Send(eMessage);
message.IsSent = true;
return true;
}
catch (Exception ex)
{
message.IsSent = false;
return false;
}
}
示例4: StartWork
public void StartWork()
{
if (emailEntry.State == WorkState.Success)
{
OnWorkCompleted(WorkState.Success);
return;
}
if (!emailEntry.IsValid)
{
OnWorkCompleted(emailEntry.State);
return;
}
emailEntry.State = WorkState.InProgress;
var message = new EmailMessage(emailEntry.RecipientAddress, emailEntry.EmailSubject, emailEntry.EmailContent, settingsRepository.GetSettings().SenderEmailAddress);
messageId = message.MessageId;
apiExtension.SendMessageAsync(message, result =>
{
switch (result.RoutingState)
{
case RoutingState.DestinationAccepted:
if (emailEntry.State == WorkState.InProgress)
emailEntry.State = WorkState.Routed;
break;
case RoutingState.DestinationNotFound:
OnWorkCompleted(WorkState.DeliveringFailed);
apiExtension.MessageSubmitted -= apiExtension_MessageSubmitted;
break;
}
});
}
示例5: ComposeEmail
public void ComposeEmail(IEnumerable<string> to, IEnumerable<string> cc = null, string subject = null, string body = null, bool isHtml = false,
IEnumerable<EmailAttachment> attachments = null, string dialogTitle = null)
{
var message = new EmailMessage
{
Subject = subject,
Body = body
};
foreach (var recipient in to)
{
message.To.Add(new EmailRecipient(recipient));
}
if (cc != null)
{
foreach (var recipient in cc)
{
message.CC.Add(new EmailRecipient(recipient));
}
}
if (attachments != null)
{
foreach (var attachment in attachments)
{
var stream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromStream(attachment.Content.AsRandomAccessStream());
message.Attachments.Add(new Windows.ApplicationModel.Email.EmailAttachment(attachment.FileName, stream));
}
}
EmailManager.ShowComposeNewEmailAsync(message);
}
示例6: SendThread
public static void SendThread()
{
//create SMTP object
SMTP objSMTP = new SMTP();
objSMTP.SMTPServers.Add("smtp.socketlabs.com", 25, 60, SMTPAuthMode.AuthLogin, "your_smtp_user", "your_smtp_password");
/*
* this sample just sends one message per thread/connection but in the real world you should send about
* 50-100 messages per connection. You will have to add your database retrieval and loop management here
*
* i.e. grab 50 records from db, connect, loop through and send all 50 and then disconnect
* repeat as long as there are more records to process in database
*/
//establish connection and keep it open for all messages we send
objSMTP.Connect();
EmailMessage objMessage = new EmailMessage();
objMessage.From = new Address("[email protected]", "Sender Name");
objMessage.Recipients.Add("[email protected]", "Recipient Name", RecipientType.To);
objMessage.Subject = "Subject...";
objMessage.BodyParts.Add("Hi ##FIRSTNAME##, Thank you for your interest in ##PRODUCT##.", BodyPartFormat.Plain, BodyPartEncoding.QuotedPrintable);
Dictionary<string, string> tokens = new Dictionary<string, string>();
tokens["##FIRSTNAME##"] = "John";
tokens["##PRODUCT##"] = "SocketLabs Email On-Demand";
objMessage.BodyParts[0].Body = BulkReplace(objMessage.BodyParts[0].Body, tokens);
objSMTP.Send(objMessage);
//close connection after all messages have been sent
objSMTP.Disconnect();
Interlocked.Decrement(ref threadsOpen);
}
示例7: Developer_Click
private async void Developer_Click(object sender, RoutedEventArgs e)
{
EmailMessage emailMessage = new EmailMessage();
emailMessage.To.Add(new EmailRecipient("[email protected]"));
await EmailManager.ShowComposeNewEmailAsync(emailMessage);
}
示例8: Main
static void Main() {
Console.WriteLine("Start of publisher");
Bus.Initialize(cfg => {
cfg.ReceiveFrom("msmq://localhost/mytestqueue");
cfg.UseMsmq(mq => mq.UseMulticastSubscriptionClient());
cfg.VerifyMsDtcConfiguration();
});
IServiceBus bus = Bus.Instance;
for (;;) {
Console.Write("Messsage: ");
string text = Console.ReadLine();
if (string.IsNullOrEmpty(text))
break;
char command = text.ToLower()[0];
string name = text.Substring(1);
switch (command) {
case 'e':
var emailMessage = new EmailMessage { Name = name, EmailAddress = "[email protected]" };
bus.Publish(emailMessage);
break;
case 'p':
var phoneMessage = new PhoneMessage {Name = name, Received = DateTime.Now, PhoneNumber = "(212) 555-1212"};
bus.Publish(phoneMessage);
break;
default:
Console.WriteLine("Preceed message with e for email or p for phone call.");
break;
}
}
}
示例9: Insert
///<summary>Inserts one EmailMessage into the database. Returns the new priKey.</summary>
internal static long Insert(EmailMessage emailMessage)
{
if(DataConnection.DBtype==DatabaseType.Oracle) {
emailMessage.EmailMessageNum=DbHelper.GetNextOracleKey("emailmessage","EmailMessageNum");
int loopcount=0;
while(loopcount<100){
try {
return Insert(emailMessage,true);
}
catch(Oracle.DataAccess.Client.OracleException ex){
if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
emailMessage.EmailMessageNum++;
loopcount++;
}
else{
throw ex;
}
}
}
throw new ApplicationException("Insert failed. Could not generate primary key.");
}
else {
return Insert(emailMessage,false);
}
}
示例10: OpenEmailClientWithoutPayload
public static async void OpenEmailClientWithoutPayload()
{
IDeviceInfoService _deviceInfoService = ((App)App.Current).Scope.Resolve<IDeviceInfoService>();
EmailMessage emailMessage = new EmailMessage();
var credentialsProvider = ((App)Application.Current).Scope.Resolve<ICredentialsProvider>();
var creds = credentialsProvider.ProvideCredentials(CancellationToken.None);
var catalogProvider = ((App)Application.Current).Scope.Resolve<ICatalogProvider>();
var books = await catalogProvider.GetMyBooksFromCache(CancellationToken.None);
var bookProvider = ((App)Application.Current).Scope.Resolve<IBookProvider>();
var exists = await bookProvider.GetExistBooks(CancellationToken.None);
var stringBuilder = new StringBuilder();
emailMessage.To.Add(new EmailRecipient("[email protected]"));
emailMessage.Body = stringBuilder.ToString();
try
{
await EmailManager.ShowComposeNewEmailAsync(emailMessage);
}
catch (Exception e)
{
return;
}
}
示例11: Contact
public ActionResult Contact(ContactForm contactForm)
{
JsonNetResult jsonNetResult = new JsonNetResult();
jsonNetResult.Formatting = Formatting.Indented;
try
{
string subject = "Online Contact From " + contactForm.Name;
string message = contactForm.Message;
message += "\r\n\r\n " + contactForm.Name;
message += "\r\n " + contactForm.EmailAddress;
message += "\r\n " + contactForm.Number;
string sendto = Settings.Default.ContactEmail;
EmailMessage Message = new EmailMessage()
{
Message = message,
Subject = subject,
EmailAddressFrom = contactForm.EmailAddress,
ContactName = contactForm.Name,
EmailAddressTo = sendto
};
Message.SendMessage();
Message = null;
jsonNetResult.Data = new { Result = "success" };
}
catch (Exception ex)
{
jsonNetResult.Data = new { Result = "fail", Message = ex.Message };
}
return jsonNetResult;
}
示例12: GenerateProspectiveMailMessage
/// <summary>
/// Creates a MailMessage for the current MailAttribute instance.
/// </summary>
protected EmailMessage GenerateProspectiveMailMessage(MailAttributes mail)
{
//create base message
var message = new EmailMessage
{
FromName = mail.From.DisplayName,
FromEmail = mail.From.Address,
To = mail.To.Union(mail.Cc).Select(t => new EmailAddress(t.Address, t.DisplayName)),
BccAddress = mail.Bcc.Any() ? mail.Bcc.First().Address : null,
Subject = mail.Subject,
Important = mail.Priority == MailPriority.High ? true : false
};
// We need to set Reply-To as a custom header
if (mail.ReplyTo.Any())
{
message.AddHeader("Reply-To", string.Join(" , ", mail.ReplyTo));
}
// Adding content to the message
foreach (var view in mail.AlternateViews)
{
var reader = new StreamReader(view.ContentStream, Encoding.UTF8, true, 1024, true);
var body = reader.ReadToEnd();
if (view.ContentType.MediaType == MediaTypeNames.Text.Plain)
{
message.Text = body;
}
if (view.ContentType.MediaType == MediaTypeNames.Text.Html)
{
message.Html = body;
}
}
// Going through headers and adding them to the message
mail.Headers.ToList().ForEach(h => message.AddHeader(h.Key, h.Value));
// Adding the attachments
var attachments = new List<EmailAttachment>();
foreach (var mailAttachment in mail.Attachments.Select(attachment => ActionMailerNext.Utils.AttachmentCollection.ModifyAttachmentProperties(attachment.Key, attachment.Value, false)))
{
using (var stream = new MemoryStream())
{
mailAttachment.ContentStream.CopyTo(stream);
var base64Data = Convert.ToBase64String(stream.ToArray());
attachments.Add(new EmailAttachment
{
Content = base64Data,
Name = mailAttachment.Name,
Type = mailAttachment.ContentType.MediaType,
});
}
}
message.Attachments = attachments;
return message;
}
示例13: ComposeEmail
private async void ComposeEmail()
{
var email = new EmailMessage();
var recipient = new EmailRecipient("[email protected]", "Janerson Douglas");
email.To.Add(recipient);
await EmailManager.ShowComposeNewEmailAsync(email);
}
示例14: hlbFeedback_Click
private async void hlbFeedback_Click(object sender, RoutedEventArgs e)
{
EmailMessage emailMessage = new EmailMessage();
emailMessage.Subject = "Elementary Notes - Feedback";
emailMessage.To.Add(new EmailRecipient("[email protected]"));
await EmailManager.ShowComposeNewEmailAsync(emailMessage);
}
示例15: BuildMessageAndViews
public static MailMessage BuildMessageAndViews(EmailMessage message, out AlternateView textView, out AlternateView htmlView)
{
var smtpMessage = new MailMessage { BodyEncoding = Encoding.UTF8, From = new MailAddress(message.From) };
if(message.To.Count > 0) smtpMessage.To.Add(string.Join(",", message.To));
if(message.ReplyTo.Count > 0) smtpMessage.ReplyToList.Add(string.Join(",", message.ReplyTo));
if(message.Cc.Count > 0) smtpMessage.CC.Add(string.Join(",", message.Cc));
if(message.Bcc.Count > 0) smtpMessage.Bcc.Add(string.Join(",", message.Bcc));
htmlView = null;
textView = null;
if (!string.IsNullOrWhiteSpace(message.HtmlBody))
{
var mimeType = new ContentType("text/html");
htmlView = AlternateView.CreateAlternateViewFromString(message.HtmlBody, mimeType);
smtpMessage.AlternateViews.Add(htmlView);
}
if (!string.IsNullOrWhiteSpace(message.TextBody))
{
const string mediaType = "text/plain";
textView = AlternateView.CreateAlternateViewFromString(message.TextBody, smtpMessage.BodyEncoding, mediaType);
textView.TransferEncoding = TransferEncoding.SevenBit;
smtpMessage.AlternateViews.Add(textView);
}
return smtpMessage;
}