本文整理汇总了C#中System.Net.Mail.MailAddress类的典型用法代码示例。如果您正苦于以下问题:C# MailAddress类的具体用法?C# MailAddress怎么用?C# MailAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MailAddress类属于System.Net.Mail命名空间,在下文中一共展示了MailAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
string displayName = string.Empty;
string address = string.Empty;
while (reader.Read())
{
var tokenType = reader.TokenType;
if (reader.TokenType == JsonToken.PropertyName)
{
var val = (reader.Value as string )?? string.Empty;
if (val == "DisplayName")
{
displayName = reader.ReadAsString();
}
if (val == "Address")
{
address = reader.ReadAsString();
}
}
if (reader.TokenType == JsonToken.EndObject)
{
break;
}
}
var mailAddress = new MailAddress(address, displayName);
return mailAddress;
}
示例2: sendMessage
private void sendMessage()
{
MailAddress adresa = new MailAddress("[email protected]");
MailMessage zpráva;
if (logFile)
{
string log;
using (StreamReader reader = new StreamReader(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Info", "Log", "logStatusBaru.log")))
{
log = reader.ReadToEnd();
}
if (log.Length > 50000)
log.Remove(50000);
zpráva = new MailMessage("[email protected]", "[email protected]", předmětTextBox.Text, textZprávyTextBox.Text + log);
}
else
{
zpráva = new MailMessage("[email protected]", "[email protected]", předmětTextBox.Text, textZprávyTextBox.Text);
}
SmtpClient klient = new SmtpClient();
klient.Host = "smtp.gmail.com";
klient.Port = 465;
klient.EnableSsl = true;
//klient.Send(zpráva);
}
示例3: SendMail
public static void SendMail(string subject, string body, ICollection<string> recipients)
{
var fromAddress = new MailAddress("[email protected]", "Bearchop");
const string fromPassword = "alexander0426";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
var message = new MailMessage();
message.From = fromAddress;
message.Subject = subject;
message.Body = body;
var toList = string.Join(",", recipients);
message.To.Add(toList);
smtp.Send(message);
}
示例4: Enviar
protected void Enviar(object sender, EventArgs e)
{
MailMessage email = new MailMessage();
MailAddress de = new MailAddress(txtEmail.Text);
email.To.Add("[email protected]");
email.To.Add("[email protected]");
email.To.Add("[email protected]");
email.To.Add("[email protected]");
email.To.Add("[email protected]");
email.To.Add("[email protected]");
email.From = de;
email.Priority = MailPriority.Normal;
email.IsBodyHtml = false;
email.Subject = "Sua Jogada: " + txtAssunto.Text;
email.Body = "Endereço IP: " + Request.UserHostAddress + "\n\nNome: " + txtNome.Text + "\nEmail: " + txtEmail.Text + "\nMensagem: " + txtMsg.Text;
SmtpClient enviar = new SmtpClient();
enviar.Host = "smtp.live.com";
enviar.Credentials = new NetworkCredential("[email protected]", "");
enviar.EnableSsl = true;
enviar.Send(email);
email.Dispose();
Limpar();
ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "alert('Email enviado com sucesso!');", true);
}
示例5: SendAsync
private void SendAsync(string toStr, string fromStr, string subject, string message)
{
try
{
var from = new MailAddress(fromStr);
var to = new MailAddress(toStr);
var em = new MailMessage(from, to) { BodyEncoding = Encoding.UTF8, Subject = subject, Body = message };
em.ReplyToList.Add(from);
var client = new SmtpClient(SmtpServer) { Port = Port, EnableSsl = SslEnabled };
if (UserName != null && Password != null)
{
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(UserName, Password);
}
client.Send(em);
}
catch (Exception e)
{
Log.Error("Could not send email.", e);
//Swallow as this was on an async thread.
}
}
示例6: Send
public void Send(SPWeb web, IEnumerable<string> emailTo, string senderDisplayName, string subject, string body)
{
if (web == null) throw new ArgumentNullException("web");
if (emailTo == null || !emailTo.Any()) throw new ArgumentNullException("emailTo");
var webApplication = web.Site.WebApplication;
var from = new MailAddress(webApplication.OutboundMailSenderAddress, senderDisplayName);
var message = new MailMessage
{
IsBodyHtml = true,
Body = body,
From = from
};
var smtpServer = webApplication.OutboundMailServiceInstance;
var smtp = new SmtpClient(smtpServer.Server.Address);
foreach (var email in emailTo)
{
message.To.Add(email);
}
message.Subject = subject;
smtp.Send(message);
}
示例7: send_email_alert
public void send_email_alert(string alert_message)
{
var fromAddress = new MailAddress("[email protected]", "Selenium Alert");
var toAddress = new MailAddress("[email protected]", "Max");
const string fromPassword = "098AZQ102030";
const string subject = "Selenium Alert";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = alert_message
})
{
smtp.Send(message);
}
}
示例8: Contact
public ViewResult Contact(Contact contact)
{
if (ModelState.IsValid)
{
using (var client = new SmtpClient())
{
var adminEmail = ConfigurationManager.AppSettings["AdminEmail"];
var from = new MailAddress(adminEmail, "MatlabBlog Messenger");
var to = new MailAddress(adminEmail, "MatlabBlog Admin");
using (var message = new MailMessage(from, to))
{
message.Body = contact.Body;
message.IsBodyHtml = true;
message.BodyEncoding = Encoding.UTF8;
message.Subject = contact.Subject;
message.SubjectEncoding = Encoding.UTF8;
message.ReplyTo = new MailAddress(contact.Email);
client.Send(message);
}
}
return View("Thanks");
}
return View();
}
示例9: SendInscripcion
public static bool SendInscripcion(string email, string url, string html)
{
try
{
using (SmtpClient mailClient = new SmtpClient("smtp.office365.com", 587))
{
//Your SmtpClient gets set to the SMTP Settings you found in the "POP, IMAP, and SMTP access" section from Web Outlook
//SmtpClient mailClient = new SmtpClient("smtp.office365.com");
//Your Port gets set to what you found in the "POP, IMAP, and SMTP access" section from Web Outlook
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
//Set EnableSsl to true so you can connect via TLS
//Your network credentials are going to be the Office 365 email address and the password
mailClient.Credentials = new System.Net.NetworkCredential("[email protected]", "Admin2016");
var from = new MailAddress("[email protected]", "Administracion Cent11",System.Text.Encoding.UTF8);
var to = new MailAddress(email);
MailMessage message = new MailMessage(from, to);
message.Subject = "Formulario de Inscripcion";
message.IsBodyHtml = true;
message.Body = html;
mailClient.Send(message);
return true;
}
}
catch (Exception)
{
throw;
}
}
示例10: SendEmail
public static bool SendEmail(string EmailToAddress, string emailCCAddresses, string messageBody, string mailSubject)
{
SmtpClient client = new SmtpClient();
try
{
MailAddress maFrom = new MailAddress("[email protected]", "website", Encoding.UTF8);
MailAddress maTo = new MailAddress(EmailToAddress, EmailToAddress, Encoding.UTF8);
MailMessage mmsg = new MailMessage(maFrom.Address, maTo.Address);
mmsg.Body = messageBody;
mmsg.BodyEncoding = Encoding.UTF8;
mmsg.IsBodyHtml = true;
mmsg.Subject = mailSubject;
mmsg.SubjectEncoding = Encoding.UTF8;
if (!string.IsNullOrEmpty(emailCCAddresses))
{
mmsg.CC.Add(emailCCAddresses);
}
client.Send(mmsg);
return true;
}
catch (Exception ex)
{
ExceptionHelper.SendExceptionEmail(ex);
return false;
}
return true;
}
示例11: SendEmail
public virtual void SendEmail(EmailServerSettings settings, string subject, string body, IEnumerable<MailAddress> toAddressList, MailAddress fromAddress, params EmailAttachmentData[] attachments)
{
using (var smtpClient = GetSmtpClient(settings))
{
var message = new MailMessage();
message.From = fromAddress;
message.Body = body;
message.Subject = subject;
message.IsBodyHtml = true;
foreach (var toAddress in toAddressList)
{
message.To.Add(toAddress);
}
if (attachments != null)
{
foreach (var item in attachments)
{
var stream = StreamHelper.CreateMemoryStream(item.AttachmentData);
stream.Position = 0;
var attachment = new Attachment(stream, item.FileName);
message.Attachments.Add(attachment);
}
}
smtpClient.Send(message);
}
}
示例12: Send
public void Send(EmailContents emailContents)
{
SmtpClient client = new SmtpClient(SMTPServerName);
client.UseDefaultCredentials = true;
MailAddress from = new MailAddress(emailContents.FromEmailAddress, emailContents.FromName);
MailAddress to = new MailAddress(ToAddress);
MailAddress bcc = new MailAddress(emailContents.Bcc);
MailAddress cc = new MailAddress(emailContents.Cc);
MailMessage message = new MailMessage(from, to);
message.Bcc.Add(bcc);
message.CC.Add(cc);
message.Subject = emailContents.Subject;
message.Body = Utilities.FormatText(emailContents.Body, true);
message.IsBodyHtml = true;
try
{
client.Send(message);
IsSent = true;
}
catch (Exception ex)
{
throw ex;
}
}
示例13: Index
public ActionResult Index(string name, string email, string phone, string message)
{
try
{
//Create the msg object to be sent
MailMessage msg = new MailMessage();
//Add your email address to the recipients
msg.To.Add("[email protected]");
//Configure the address we are sending the mail from
MailAddress address = new MailAddress("[email protected]");
msg.From = address;
msg.Subject = "Website Feedback";
string body = "From: " + name + "\n";
body += "Email: " + email + "\n";
body += "phone: " + phone + "\n\n";
body += message + "\n";
msg.Body = body;
SmtpClient client = new SmtpClient();
client.Host = "relay-hosting.secureserver.net";
client.Port = 25;
//Send the msg
client.Send(msg);
ViewBag.msg = "Mail Sent. Thank You For Contacting Us.";
return View();
}
catch(Exception)
{
ViewBag.msg = "Something Is Wrong. Try Again.";
return View();
}
}
示例14: SendMail
/// <summary>
/// Use to send messages via e-mail to specific account.
/// </summary>
/// <param name="acc">Account , to which e-mail will be sended.</param>
/// <param name="text">Sended text</param>
/// <param name="sub">Subject of letter</param>
public static void SendMail(Account acc, string text,string sub)
{
MailAddress fromAddress = new MailAddress("[email protected]", "SolarAnalys");
var toAddress = new MailAddress(acc.Email);
string fromPassword = "C4llMeIsmael";
//AccountSecurityToken token = new AccountSecurityToken(acc);
string subject=sub??"", body= text??"";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
message.IsBodyHtml = true;
smtp.Send(message);
}
}
示例15: Send_Click
private void Send_Click(object sender, EventArgs e)
{
try
{
Output.Text = string.Empty;
FileInfo file = new FileInfo(_file);
StreamReader rdr = file.OpenText();
string messageBody = rdr.ReadToEnd();
rdr.Dispose();
SmtpClient client = new SmtpClient("some.mail.server.example.com");
client.Credentials = new NetworkCredential("someuser", "somepassword");
MailAddress from = new MailAddress("[email protected]");
MailAddress to = new MailAddress("[email protected]");
MailMessage msg = new MailMessage(from, to);
msg.Body = messageBody;
msg.Subject = "Test message";
//client.Send(msg);
Output.Text = "Sent email with body: " + Environment.NewLine + messageBody;
}
catch (Exception ex)
{
Output.Text = ex.ToString();
}
}