zoukankan      html  css  js  c++  java
  • 几个小技巧:发送邮件,获取客户IP,获取CreateUserWizardStep中的控件

    1. 发送邮件

    发送邮件主要使用 System.Net.Mail 下的两个类。

    public static bool Send(string rec,string recName)
    {
        MailMessage msg = new MailMessage();
        msg.To.Add(new MailAddress(rec));
        msg.From = new MailAddress(MailConfigure.Sender, MailConfigure.SenderName, Encoding.UTF8);
    
        msg.Subject = MailConfigure.Title;
        msg.SubjectEncoding = Encoding.UTF8;
        msg.Body = “Message body goes here”;
        msg.BodyEncoding = Encoding.UTF8;
        msg.IsBodyHtml = false;
    
        SmtpClient client = new SmtpClient();
        client.Credentials = new System.Net.NetworkCredential(MailConfigure.Sender, MailConfigure.SenderPwd);
        client.Port = 587;  //465 or 587 
        client.Host = MailConfigure.SMTPServer;
    
        client.EnableSsl = true;    //经过SSL加密
    
        object userState = msg;
    
        try
        {
            client.Send(msg);
            return true;
        }
        catch (SmtpException ex)
        {
            Logger.Log(ex);
        }
        return false;
    }

    2. 获取客户IP

    string ip = System.Web.HttpContext.Current.Request.UserHostAddress;

    3. 获得CreateUserWizardStep中的控件。如果在CreateUserWizardStep中放置了自己的控件,在代码中是取不到的。如果要获取可以使用如下代码:

    Control_UserProfile p = CreateUserWizard1.WizardSteps[0].Controls[0].FindControl("UserProfile1" ) as Control_UserProfile;

     

  • 相关阅读:
    要求两个条件都为假时,执行某些操作
    Celery + RabbitMq 示意图
    关于消息队列的好文章
    django related_name, on_delete
    Celery 图,[转]
    django model 中 meta子类详解
    django 自定义app
    python __dict__
    Python SQLAlchemy基本操作和常用技巧(包含大量实例,非常好)【转】
    scala private
  • 原文地址:https://www.cnblogs.com/yinzixin/p/1726001.html
Copyright © 2011-2022 走看看