本文整理汇总了C#中Mail类的典型用法代码示例。如果您正苦于以下问题:C# Mail类的具体用法?C# Mail怎么用?C# Mail使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Mail类属于命名空间,在下文中一共展示了Mail类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnSubmit_Click
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (!Page.IsValid) return;
int receiverID=(int)ViewState["receiverID"];
using (MooDB db = new MooDB())
{
Mail mail=new Mail()
{
From = ((SiteUser)User.Identity).GetDBUser(db),
To = (from u in db.Users
where u.ID == receiverID
select u).Single<User>(),
Title = txtTitle.Text,
Content = txtContent.Text,
IsRead = false,
};
db.Mails.AddObject(mail);
db.SaveChanges();
Logger.Info(db,string.Format("向用户#{0}发送邮件#{1}",receiverID,mail.ID));
}
PageUtil.Redirect("创建成功", "~/Mail/List.aspx");
}
示例2: SubmitBtn_Click
protected void SubmitBtn_Click(object sender, EventArgs e)
{
AccessDB dbObj = new AccessDB();
dbObj.Open();
dbObj.Query = string.Format("Select emailaddress,CAST( AES_DECRYPT( passwd, 'kalli' ) AS CHAR( 100 ) ) from tbluserlogin where emailaddress ='{1}'", Constants.AESKey, UserNameTbx.Text);
dbObj.ExecuteQuery();
if (dbObj.Dataset.Tables[0].Rows.Count > 0)
{
Mail mailObj = new Mail();
mailObj.To = UserNameTbx.Text;
mailObj.Subject = "Reply: Forgot Password Request";
mailObj.MailBody = string.Format("Dear Ma'am/Sir, \r\n Username:{0} \r\n Password:{1} \r\n Regards, \r\n Admin team.", UserNameTbx.Text, dbObj.Dataset.Tables[0].Rows[0][1]);
mailObj.SendMailMessage();
VerificationLbl.Text = "Your password has been sent to your email.";
VerificationLbl.Visible = true;
}
else
{
VerificationLbl.Text = "The UserName provided is not valid.Kindly verify and retry / contact the Admin Team.";
VerificationLbl.Visible = true;
}
dbObj.Close();
}
示例3: createComentario
public Mensaje createComentario([FromBody]UtilsJson.AContacto comentario)
{
Mensaje mensaje = null;
try
{
//datos logueo
string nombre = comentario.nombre_contacto;
string telefono = comentario.telefono_contacto;
string email = comentario.email_contacto;
string messangeC = comentario.comentario_contacto;
Contacto contacto = new Contacto(nombre, telefono, email, messangeC);
contacto.fecha_ult_modificacion = DateTime.Now;
_repositorio.SaveOrUpdate(contacto);
//Envio email confirmacion para habilitar el perfil
StringBuilder bodyMail = new StringBuilder();
bodyMail.AppendLine("Comentario enviado por: " + nombre);
bodyMail.AppendLine("Telefono: " + telefono);
bodyMail.Append(comentario);
string subject = "Comentario o sugerencia. " + email;
Mail mail = new Mail("[email protected]", subject, bodyMail);
mail.sendMail();
mensaje = new Mensaje(EnumTipoMensaje.Notificacion, "Notificación", "Comentario procesado exitosamente.");
}
catch (Exception ex)
{
mensaje = new Mensaje(EnumTipoMensaje.Error, "Error", "Ocurrio un error mientras se procesaba su solicitud.");
}
return mensaje;
}
示例4: SaveRead_Test
public void SaveRead_Test()
{
var mail = new Mail(logger);
var mlName = "1ban";
MlDb mlDb = new MlDb(logger, dir,mlName);
mlDb.Remove();//もし、以前のメールが残っていたらTESTが誤動作するので、ここで消しておく
Assert.AreEqual(mlDb.Count(), 0);
var max = 10;//試験件数10件
//保存と、
for (int i = 0; i < max; i++) {
var b = mlDb.Save( mail);
Assert.AreEqual(b,true);//保存が成功しているか
Assert.AreEqual(mlDb.Count(), i+1);//連番がインクリメントしているか
}
//範囲外のメール取得でnullが返るか
//no==1..10が取得可能
var m = mlDb.Read(0);//範囲外
Assert.IsNull(m);
//範囲内
for (int no = 1; no <= max; no++) {
m = mlDb.Read(no);
Assert.NotNull(mlDb.Read(no));
}
//範囲外
m = mlDb.Read(11);
Assert.IsNull(m);
mlDb.Remove();
}
示例5: SendAsync
public async Task SendAsync(IdentityMessage message)
{
//var myMessage = new SendGridMessage();
//myMessage.AddTo(message.Destination);
//myMessage.From = new MailAddress("[email protected]", "fzrain");
//myMessage.Subject = message.Subject;
//myMessage.Text = message.Body;
//myMessage.Html = message.Body;
//var credentials = new NetworkCredential("fzy55601", "fzy86087108");
//// Create a Web transport for sending email.
//var transportWeb = new Web(credentials);
//// Send the email.
//await transportWeb.DeliverAsync(myMessage);
String apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGridAPIClient(apiKey);
Email from = new Email("[email protected]");
String subject = "Hello World from the SendGrid CSharp Library";
Email to = new Email("[email protected]");
Content content = new Content("text/plain", "Textual content");
Mail mail = new Mail(from, subject, to, content);
dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
}
示例6: Index
public IActionResult Index(Mail Data)
{
if (ModelState.IsValid)
{
StringBuilder message = new StringBuilder();
MailAddress from = new MailAddress(Data.Email);
message.Append("Name: " + Data.Name + "\n");
message.Append("Email: " + Data.Email + "\n");
message.Append("Subject: " + Data.Subject + "\n");
message.Append("Subject: \n" + Data.Message);
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "K33ls3n2188#");
smtp.EnableSsl = true;
mail.From = from;
mail.To.Add("[email protected]");
mail.Subject = "Keelsen Contact Form: " + Data.Subject + " (" + Data.Email + ")";
mail.Body = message.ToString();
smtp.Send(mail);
Data.Done = true;
}
return View(Data);
}
示例7: SubmitBtn_Click
protected void SubmitBtn_Click(object sender, ImageClickEventArgs e)
{
Mail mailObj = new Mail();
mailObj.MailBody = CommentTB.Text;
//Will by default have the from address as '[email protected]'
mailObj.From = Session["UserLogin"].ToString();
mailObj.Subject = string.Format("{0}:{1}", Session["UserLogin"].ToString(), ReasonDDL.SelectedValue);
mailObj.To = ConfigurationManager.AppSettings["AdminEmail"];
mailObj.SendMailMessage();
#region mailToAllAdmins
//Send to all Admins ..
// AccessDB dbObj = new AccessDB();
// dbObj.Open();
/*dbObj.Dataset.Reset();
dbObj.Query = string.Format(@"Select emailaddress from tbluserlogin where isadmin=true");
dbObj.ExecuteQuery();
for (int i = 0; i < dbObj.Dataset.Tables[0].Rows.Count; i++)
{
mailObj.To = dbObj.Dataset.Tables[0].Rows[i][0].ToString();
mailObj.SendMailMessage();
}*/
#endregion
ConfMsgLbl.Visible = true;
}
示例8: GetEmailBody
public static string GetEmailBody(Mail emailName, object model)
{
var templatePath = physicalApplicationPath + @"Views\EmailTemplates\" + emailName + ".cshtml";
var template = System.IO.File.ReadAllText(templatePath, System.Text.Encoding.Default);
return Razor.Parse(template, model);
}
示例9: DoBuildAndSendMail
// tag::buildAndSendMail[]
public void DoBuildAndSendMail(MailMan m, MailAddress mAddress,
MailBody mBody) {
// Build the mail
Mail mail = new Mail(mAddress, mBody);
// Send the mail
m.SendMail(mail);
}
示例10: Send
public static void Send(Mail mail)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress(mail.From, "Money Pacific Service");
msg.To.Add(new MailAddress(mail.To));
msg.Subject = mail.Subject;
msg.Body = mail.Body;
msg.IsBodyHtml = true;
msg.BodyEncoding = new System.Text.UTF8Encoding();
msg.Priority = MailPriority.High;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
System.Net.NetworkCredential user = new
System.Net.NetworkCredential(
ConfigurationManager.AppSettings["sender"],
ConfigurationManager.AppSettings["senderPass"]
);
smtp.EnableSsl = true;
smtp.Credentials = user;
smtp.Port = 587; //or use 465
object userState = msg;
try
{
//you can also call client.Send(msg)
smtp.SendAsync(msg, userState);
}
catch (SmtpException)
{
//Catch errors...
}
}
示例11: Create
public object Create(object parent, object configContext, System.Xml.XmlNode section)
{
Mail mail = new Mail();
mail.StaffDomain = section.Attributes["staffDomain"] != null ? section.Attributes["staffDomain"].Value : mail.StaffDomain;
return mail;
}
示例12: Handle
public async Task Handle(SendMail command, IAggregateRepository repository)
{
var mail = new Mail();
mail.RequestMail(command);
await repository.Create(mail.RaiseNewEvents());
await mail.SendMail(this.mailService);
await repository.Update(mail.RaiseNewEvents());
}
示例13: SendEmail
public static async Task SendEmail(string email, string subject, string content, EmailConfig config)
{
dynamic sg = new SendGridAPIClient(config.SendGridApiKey);
Email from = new Email(config.EmailFrom);
Email to = new Email(email);
Mail mail = new Mail(from, subject, to, new Content("text/html", content));
dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
}
示例14: GlimpseMail
public GlimpseMail(Mail Mail)
{
if (Mail != null) {
this.ToEmail = Mail.ToEmail;
this.ToName = Mail.ToName;
this.Subject = Mail.Subject;
this.Body = Mail.Body;
}
}
示例15: Test_New
public void Test_New()
{
var from = new Node ("Node1");
var mail = new Mail (from, "Node2", "Hello World");
Assert.AreEqual (from, mail.From);
Assert.AreEqual ("Node2", mail.Address);
Assert.AreEqual ("Hello World", mail.Letter);
}