本文整理汇总了C#中MimeKit.MimeMessage类的典型用法代码示例。如果您正苦于以下问题:C# MimeMessage类的具体用法?C# MimeMessage怎么用?C# MimeMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MimeMessage类属于MimeKit命名空间,在下文中一共展示了MimeMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendEmailAsync
public async Task SendEmailAsync(string email, string subject, string message)
{
var emailMessage = new MimeMessage();
emailMessage.From.Add(new MailboxAddress(_settings.Value.Author, _settings.Value.Email));
emailMessage.To.Add(new MailboxAddress("", email));
emailMessage.Subject = subject;
emailMessage.Body = new TextPart("html") {Text = message};
try
{
var client = new SmtpClient();
// {
// client.Connect("smtp.gmail.com", 587, SecureSocketOptions.Auto);
// client.Authenticate(_settings.Value.Email, _settings.Value.Password);
// client.Send(emailMessage);
// client.Disconnect(true);
await client.ConnectAsync("smtp.gmail.com", 587, SecureSocketOptions.Auto);
await client.AuthenticateAsync(_settings.Value.Email, _settings.Value.Password);
await client.SendAsync(emailMessage);
await client.DisconnectAsync(true);
// }
}
catch (Exception ex) //todo add another try to send email
{
var e = ex;
throw;
}
}
示例2: SendMessage
public void SendMessage() {
string msg = "";
switch (CurrEmailType) {
case EmailType.PRENOTA:
msg = PrenotaSubject;
FromMailAddress = PrenotaFromAddress;
break;
case EmailType.INFO:
msg = InfoSubject;
FromMailAddress = InfoFromAddress;
break;
}
string subject = string.Format(msg, Message.Nome, DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));
string body = string.Format("Nome : {0}\nNumero : {1}\nE-Mail : {2}\nMessaggio :\n{3}", Message.Nome, Message.Telefono, Message.Email, Message.Messaggio);
var message = new MimeMessage();
message.From.Add(FromMailAddress);
message.To.Add(ToAddress);
message.Subject = subject;
message.Body = new TextPart("plain") {Text = body};
try {
using (var client = new SmtpClient()) {
client.Connect("smtp.gmail.com", 465, true);
client.AuthenticationMechanisms.Remove("XOAUTH");
client.Authenticate("[email protected]", "At066bn1!");
client.Send(message);
client.Disconnect(true);
}
Result = EmailResult.SUCCESS;
MessageResult = "Messaggio inviato correttamente";
} catch (Exception ex) {
Result = EmailResult.FAIL;
MessageResult = ex.Message;
}
}
示例3: SendEmail
/// <summary>
/// MAIL KIT
/// Info : http://dotnetthoughts.net/how-to-send-emails-from-aspnet-core/
/// </summary>
public static void SendEmail(string email, string name, string subject, string message,byte[] attachment = null,string attachmentName ="Facture")
{
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress(Configurations.Application.StolonsLabel, Configurations.Application.MailAddress));
mimeMessage.To.Add(new MailboxAddress(name, email));
mimeMessage.Subject = subject;
var bodyBuilder = new BodyBuilder();
if(attachment != null)
bodyBuilder.Attachments.Add(attachmentName,attachment);
bodyBuilder.HtmlBody = message;
mimeMessage.Body = bodyBuilder.ToMessageBody();
try
{
using (var client = new SmtpClient())
{
client.Connect(Configurations.Application.MailSmtp, Configurations.Application.MailPort, false);
client.AuthenticationMechanisms.Remove("XOAUTH2");
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.Authenticate(Configurations.Application.MailAddress, Configurations.Application.MailPassword);
client.Send(mimeMessage);
client.Disconnect(true);
}
}
catch (Exception except)
{
Console.WriteLine("Error on sending mail : " + except.Message);
}
}
示例4: Simple
public static void Simple ()
{
#region Simple
var message = new MimeMessage ();
message.From.Add (new MailboxAddress ("Joey", "[email protected]"));
message.To.Add (new MailboxAddress ("Alice", "[email protected]"));
message.Subject = "How you doin?";
var builder = new BodyBuilder ();
// Set the plain-text version of the message text
builder.TextBody = @"Hey Alice,
What are you up to this weekend? Monica is throwing one of her parties on
Saturday and I was hoping you could make it.
Will you be my +1?
-- Joey
";
// We may also want to attach a calendar event for Monica's party...
builder.Attachments.Add (@"C:\Users\Joey\Documents\party.ics");
// Now we just need to set the message body and we're done
message.Body = builder.ToMessageBody ();
#endregion
}
示例5: Generic
public static void Generic(string[] args)
{
MainActivity = new MainActivity ();
var message = new MimeMessage ();
message.From.Add (new MailboxAddress ("test", "[email protected]"));
message.To.Add (new MailboxAddress (MainActivity.nome, MainActivity.email));
message.Subject = "Obrigado por se candidatar";
message.Body = new TextPart ("plain") {
Text = @"Obrigado por se candidatar, assim que tivermos uma vaga disponível
para programador entraremos em contato."
};
using (var client = new SmtpClient ()) {
client.Connect ("smtp.test.com", 587, false);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove ("XOAUTH2");
// Note: only needed if the SMTP server requires authentication
client.Authenticate ("test", "password");
client.Send (message);
client.Disconnect (true);
}
}
示例6: IsRuleMatching
public static bool IsRuleMatching(MimeMessage message, Rule rule) {
var fromAddress = message.From.Cast<MailboxAddress>().First().Address;
switch (rule.Type) {
case RuleType.SenderEquals:
return fromAddress == rule.Value;
case RuleType.SenderContains:
return fromAddress.Contains(rule.Value);
case RuleType.SenderEndsWith:
return fromAddress.EndsWith(rule.Value);
case RuleType.SubjectContains:
return message.Subject.Contains(rule.Value);
case RuleType.SubjectEquals:
return message.Subject == rule.Value;
case RuleType.SubjectBeginsWith:
return message.Subject.StartsWith(rule.Value);
case RuleType.SubjectEndsWith:
return message.Subject.EndsWith(rule.Value);
}
return false;
}
示例7: MessageViewModel
public MessageViewModel(MimeMessage message)
{
_msg = message;
var pvm = new PartViewModel(message.Body);
pvm.IsExpanded = true;
_main = new[] {pvm};
}
示例8: Should_return_multiple_emails_when_sent
public async Task Should_return_multiple_emails_when_sent()
{
using (var sut = GetSut())
{
var msg = new MimeMessage();
msg.From.Add(new MailboxAddress("", "[email protected]"));
msg.To.Add(new MailboxAddress("", "[email protected]"));
msg.Subject = "subject";
msg.Body = new TextPart("plain") {Text = "body"};
var msg2 = new MimeMessage();
msg2.From.Add(new MailboxAddress("", "[email protected]"));
msg2.To.Add(new MailboxAddress("", "[email protected]"));
msg2.Subject = "subject2";
msg2.Body = new TextPart("plain") {Text = "body2"};
var emails =
(await
GetEmails(sut, s => s.GetEmails(), () => SendEmailsAsync(sut, msg), () => SendEmailsAsync(sut, msg2)))
.ToList();
Assert.That(emails.Count, Is.EqualTo(2));
AssertEmailsAreEqual(emails[0], msg2);
AssertEmailsAreEqual(emails[1], msg);
}
}
示例9: Send
public void Send(EmailDependencies email)
{
try
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress(email.FromName, email.FromAddress));
message.To.Add(new MailboxAddress(email.ToName, email.ToAddress));
message.To.Add(new MailboxAddress(email.FromName, email.FromAddress));
message.Subject = email.Title;
message.Body = new TextPart("html") { Text = email.content };
using (var client = new SmtpClient())
{
client.Connect("mail.bizmonger.net", 587, false);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
// Note: only needed if the SMTP server requires authentication
client.Authenticate(Configuration.ServerEmail, Configuration.Password);
client.Send(message);
client.Disconnect(true);
}
}
catch (Exception ex)
{
var errorMessage = ex.GetBaseException().Message;
Debug.WriteLine(errorMessage);
}
}
示例10: Detect
/// <summary>
/// detects whether a message is a qmail (QSBMF) bounce message.
/// </summary>
///
/// See The qmail-send Bounce Message Format (QSBMF):
/// http://cr.yp.to/proto/qsbmf.txt
public static BounceDetectResult Detect(MimeMessage message)
{
//
// detect on a text part.
var textPart = message.Body as TextPart;
if (textPart != null)
{
var result = DetectQmailBounce(message, textPart);
if (result != null)
return result;
}
//
// detect on a multipart.
var multipart = message.Body as MultipartAlternative;
return multipart?
.OfType<TextPart>()
.Select(p => DetectQmailBounce(message, p))
.FirstOrDefault();
}
示例11: EnviarAltaCuenta
public void EnviarAltaCuenta(string cuentaUsuario, string password)
{
var mensage = new MimeMessage();
mensage.From.Add(new MailboxAddress("Verum In Sanguine", "[email protected]"));
mensage.To.Add(new MailboxAddress(cuentaUsuario, cuentaUsuario));
mensage.Subject = "Cuenta de usuario en Verum In Sanguine";
mensage.Body = new TextPart("html") { Text = TextoAltaCuenta(cuentaUsuario, password) };
EnviarMensaje(mensage);
}
示例12: AnalyzeMessage
private static void AnalyzeMessage(MimeMessage message, LearningDataSet result) {
result.Adresses.AddOrIgnore(message?.Sender?.Address);
result.Subjects.AddOrIgnore(message?.Subject);
var urls = UrlParser.Parse(message?.TextBody);
foreach (var url in urls) {
result.Urls.AddOrIgnore(url);
}
}
示例13: SendAsync
public async Task SendAsync(IdentityMessage message)
{
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress("Richard Benson", "[email protected]"));
mimeMessage.To.Add(new MailboxAddress(message.Destination, message.Destination));
mimeMessage.Subject = message.Subject;
mimeMessage.Body = new TextPart("plain") { Text = message.Body };
await _mailSender.SendMailAsync(mimeMessage);
}
示例14: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
webView.ScalesPageToFit = true;
// Perform any additional setup after loading the view, typically from a nib.
Message = MimeMessage.Load (GetType ().Assembly.GetManifestResourceStream ("xamarin3.msg"));
}
示例15: MessageSentEventArgs
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.MessageSentEventArgs"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="MessageSentEventArgs"/>.
/// </remarks>
/// <param name="message">The message that was just sent.</param>
/// <param name="response">The response from the server.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="message"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="response"/> is <c>null</c>.</para>
/// </exception>
public MessageSentEventArgs (MimeMessage message, string response)
{
if (message == null)
throw new ArgumentNullException (nameof (message));
if (response == null)
throw new ArgumentNullException (nameof (response));
Message = message;
Response = response;
}