快捷搜索:

几个小技巧:发送邮件,获取客户IP,获取Creat

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;

您可能还会对下面的文章感兴趣: