Buzón de correo de la World Wide Web Newsletter smtp

No digas tonterías, la gente está ocupada

Referencia de resultado

http://www.ucsmy.net/RegistrationManage/RegistrationInfo.aspx

Necesita dominar la configuración y la llamada de web.config

La necesidad de comprender el conocimiento relacionado con Smtp es más problemática

Necesita comprender el cifrado de codificación

Entendiendo StringBuilder

html UI estética

El correo electrónico que envía aquí usa QQ

configuración web.config 

<appSettings> agregado bajo el nodo 

 <! - 发送 邮件 ->
  <add key = "dirección de correo electrónico" value = "[email protected]" />  

<! - Utiliza la contraseña independiente de QQ (PS no es la contraseña de inicio de sesión de QQ) 1 Busque la configuración del buzón de QQ 2 Busque la cuenta y haga clic para encontrar lo siguiente

POP3 / IMAP / SMTP / Exchange / CardDAV / CalDAV 服务
Encienda el servicio:
->
  <agregar clave = "email-psd" value = "cao919" />  

<! - Se utiliza el servidor de envío de QQ. Este que utiliza su empresa puede cambiar smtp.qq.com ->

  <add key = "email-host" value = "smtp.qq.com" />         

  <! - WebRoot será reemplazado por el nombre de dominio de su empresa en el futuro ->
  <add key = "webRoot" value = "http: // localhost: 8888 /" />



En segundo lugar, envíe cuando sus datos se hayan agregado correctamente

<pre name="code" class="csharp">if (IsAdd) //数据新增成功
                {
   
   
<pre name="code" class="csharp">//<span style="font-family: Arial, Helvetica, sans-serif;">user</span>
string webRoot = System.Configuration.ConfigurationManager.AppSettings ["webRoot"]. ToString (); StringBuilder urlsb = new StringBuilder (); string url = "http: // mail". + usuario.Email.Split ('@') [1]; urlsb.Append ("<div style = 'margin: 50px auto; background: # e5f5fc; border-radius: 5px 5px 5px 5px; width: 698px; height: 100%; font-size: 12px; color: # 000; overflow : oculto; '> <img src =' https: //usercenter.yihaojiaju.com/Images-2.0/common/newlogo-new.png'/> <p style = 'padding: 10px 50px 0 50px; altura de línea: 30px; '> ") .Append (" <span style =' color: # f01c1c; '> 您好! 感谢 您 使用 ** 系统。 </span> ") .Append (" <br/> ") .Append ("您 的 注册 帐号 为 : <span style = 'color: # f01c1c;'>"). Append (
user
.StaffID) .Append ("</span> Su contraseña es: <span style = 'color: # f01c1c;'>" +
user
.Pwd + "¡Cambie su contraseña después de registrarse con éxito! </span>") .Append ("<br/> <span style = 'color: # f01c1c;'> Puede usar la función multifunción después de activar su cuenta de correo electrónico. </ span> <br/> ") .Append (" <a style = 'color: # 258DCC; font-size: 11pt;' ") .Append (" href = '"+ webRoot +" Sys / Staff / StaffEmailSuccess .aspx? id = "). Adjuntar (SerializerHelper.Encrypt (
user
.StaffID.ToString ())). Append ("& LoginUser ="). Append (SerializerHelper.Encrypt (
user
.Name)). Agregar (""). Agregar (""). Agregar ("'>"). Agregar (""). Agregar ("haga clic aquí"). Agregar ("</a>"). Agregar ("Active su cuenta inmediatamente (el enlace es válido en 12 horas) <br/> <a style = 'color: # 3E83D1;'") .Append ("href = '" + webRoot + "Sys / Staff / StaffEmailSuccess. aspx? id = "). Adjuntar (SerializerHelper.Encrypt (
user
.StaffID.ToString ())). Append ("& LoginUser ="). Append (SerializerHelper.Encrypt (
user
.Name)). Append (""). Append (""). Append ("'>"). Append (webRoot + "Sys / Staff / StaffEmailSuccess.aspx? Id ="). Append (SerializerHelper.Encrypt (
user
.StaffID.ToString ())). Append ("& LoginUser ="). Append (SerializerHelper.Encrypt (
user
.Name)). Append ("</a> <br/>") .Append ("<- Si no puede hacer clic en este enlace, copie el enlace anterior en la barra de direcciones del navegador para visitar -> < br /> "). Append (" Esta carta es enviada por el sistema de MS del hogar número 1. El sistema no acepta cartas de respuesta. No responda directamente. Si tiene alguna pregunta, comuníquese con nosotros. "). ("<br/> <span style = 'font-weight: bold; font-size: 12px;'> Gracias por utilizar nuestro servicio </span> <br/>") .Append ("** <br/> Línea directa del servicio nacional: 4000-000-00 <br /> ") .Append (" </p> <div style = 'height: 39px; background: # 099be6; color: #fff; font-size: 16px; text- align: center; line-height: 39px; '> cao919 / div> "). Append (" </div> ");

 
 
//调用下面的方法
                    bool sendEmail = BaseComm.Email_Send(<pre name="code" class="csharp">user
.Email, "Por favor, active [*** system]", urlsb.ToString ()); string Message = "<script language = javascript>"; Message + = "if (confirm (\" ha ingresado exitosamente al personal! Continuar ingresando ? \ ")) {"; Mensaje + = "window.location.href = \" userAdd.aspx? "; Mensaje + ="} else {parent.location.reload ();} "; Mensaje + =" </ script> "; Response.Write (Mensaje);}
 
 
 
 


Ayuda necesaria para el segundo paso

 BaseComm类

<pre name="code" class="csharp">/// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="MessageTo"></param>
        /// <param name="MessageSubject"></param>
        /// <param name="MessageBody"></param>
        /// <returns></returns>
        public static bool Email_Send(string MessageTo, string MessageSubject, string MessageBody)
        {
            Regex r = new Regex("^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$");
            if (!r.IsMatch(MessageTo))
                return false;
            if (string.IsNullOrEmpty(MessageTo))
                return false;
            MailMessage message = new MailMessage();
            string fromAddress = ConfigurationManager.AppSettings["email-Address"];
            string psd = ConfigurationManager.AppSettings["email-psd"];
            message.From = new MailAddress(fromAddress, "MS系统");
            try
            {
                message.To.Add(MessageTo); //收件人邮箱地址可以是多个以实现群发  
            }
            catch
            {
                return false;
            }
            message.Subject = MessageSubject;
            message.Body = MessageBody;
            message.IsBodyHtml = true; //是否为html格式  
            message.Priority = MailPriority.High; //发送邮件的优先等级  
            SmtpClient sc = new SmtpClient();
            sc.Host = ConfigurationManager.AppSettings["email-Host"]; //指定发送邮件的服务器地址或IP  
            sc.Port = 25; //指定发送邮件端口  
            sc.Credentials = new System.Net.NetworkCredential(fromAddress, psd); //指定登录服务器的用户名和密码(发件人的邮箱登陆密码)
            try
            {
                sc.Send(message); //发送邮件  
            }
            catch (Exception ex)
            {
              //  LogHelper(new Guid().ToString(), 1);
                return false;
            }
            return true;

        }


 
 

Tres métodos de ayuda para el cifrado y el descifrado

Clase SerializerHelper

 /// <summary>
    /// 加密Token
    /// </summary>
    /// <param name="token">明文Token</param>
    /// <returns>加密的Token</returns>
    public static string Encrypt(string content)
    {
        if (string.IsNullOrEmpty(content))
        {
            return string.Empty;
        }
        Byte[] bytes = Encoding.UTF8.GetBytes(content);
        //把8位字节数组转换成Base64字符串  
        return Convert.ToBase64String(bytes);
    }
    /// <summary>
    /// 解密Token
    /// </summary>
    /// <param name="token">密文Token</param>
    /// <returns>解密的Token</returns>
    public static string Decrypt(string content)
    {
        if (string.IsNullOrEmpty(content))
        {
            return string.Empty;
        }
        byte[] tokenByte = Convert.FromBase64String(content);
        //把Base64字符串转换成8位字节数组
        return Encoding.UTF8.GetString(tokenByte);
    }


Supongo que te gusta

Origin blog.csdn.net/cao919/article/details/46855947
Recomendado
Clasificación