您的位置:首页 > 其它

几个小技巧:发送邮件,获取客户IP,获取CreateUserWizardStep中的控件

2010-05-02 16:42 489 查看
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;



 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: