给用户发电子邮件 [英] email to user

查看:77
本文介绍了给用户发电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在设计一个页面,管理员可以在其中接受或拒绝
用户先前提交的数据.该数据包括用户的电子邮件ID(编辑者注意:您的意思是地址吗?).
如果管理员按下拒绝",则会向该用户发送一封电子邮件,其中带有
静态原因.
有人可以帮我吗?

谢谢!

Hi all,

I''m designing a page where an administrator can accept or deny
data that was previously submitted by an user. That data includes the users email id (Editors note: Did you mean address?).
If the admin presses "Deny" an email will be sent to that user with a
static reason.

Can anybody help me?

Thanks you!

推荐答案

在.cs文件中使用以下代码

Use the following code in your .cs file

MailHelper.SendMailMessage("fromAddress@yourdomain.com", "toAddress@yourdomain.com", "bccAddress@yourdomain.com", "ccAddress@yourdomain.com", "Sample Subject", "Sample body of text for mail message")



创建一个类并在其中添加SendMailMessage函数.



Create a class and add SendMailMessage function in it.

using System.Net.Mail;

public class MailHelper
{
   /// <summary>
   /// Sends an mail message
   /// </summary>
   /// <param name="from">Sender address</param>
   /// <param name="to">Recepient address</param>
   /// <param name="bcc">Bcc recepient</param>
   /// <param name="cc">Cc recepient</param>
   /// <param name="subject">Subject of mail message</param>
   /// <param name="body">Body of mail message</param>
   public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
   {
      // Instantiate a new instance of MailMessage
      MailMessage mMailMessage = new MailMessage();

      // Set the sender address of the mail message
      mMailMessage.From = new MailAddress(from);
      // Set the recepient address of the mail message
      mMailMessage.To.Add(new MailAddress(to)); 
      // Check if the bcc value is null or an empty string
      if ((bcc != null) && (bcc != string.Empty))
      {
         // Set the Bcc address of the mail message
         mMailMessage.Bcc.Add(new MailAddress(bcc));
      }

      // Check if the cc value is null or an empty value
      if ((cc != null) && (cc != string.Empty))
      {
         // Set the CC address of the mail message
         mMailMessage.CC.Add(new MailAddress(cc));
      }       // Set the subject of the mail message
      mMailMessage.Subject = subject;
      // Set the body of the mail message
      mMailMessage.Body = body; 
      // Set the format of the mail message body as HTML
      mMailMessage.IsBodyHtml = true;
      // Set the priority of the mail message to normal
      mMailMessage.Priority = MailPriority.Normal;

      // Instantiate a new instance of SmtpClient
      SmtpClient mSmtpClient = new SmtpClient();
      // Send the mail message
      mSmtpClient.Send(mMailMessage);
   }
}


这篇关于给用户发电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆