/// <summary> /// 发送邮件 /// </summary> /// <param name="fromEmails">收件人地址</param> /// <param name="myEmail">发件人地址</param> /// <param name="name">发件人名字</param> /// <param name="title">邮件标题</param> /// <param name="conent">邮件内容</param> /// <returns></returns> public static Boolean SendMail(String[] fromEmails, String myEmail, String name, String title, String content) { try { System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); foreach (String email in fromEmails) { msg.To.Add(email); } msg.From = new MailAddress(myEmail, name); /* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/ msg.Subject = title;//邮件标题 msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码 msg.Body = content;//邮件内容 msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码 msg.IsBodyHtml = true;//是否是HTML邮件 msg.Priority = System.Net.Mail.MailPriority.High; SmtpClient client = new SmtpClient(); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(myEmail, "");//比如用szmorning.com.cn的用户名和密码 client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;//重点在这里,有三个可选的,之前是用Network发送,老是验证失败,改为PickupDirectoryFromIis本地IIS就OK了 client.Send(msg); return true; } catch (System.Net.Mail.SmtpException ex) { String message = ex.Message; return false; } }还需配置:<system.net> <mailSettings> <smtp> <!--<network host="mail.chevroletsingapore.com" userName="admin@chevroletsingapore.com" password="password"/>--> <network host="邮件服务器地址"/> //163.com </smtp> </mailSettings> </system.net>
判断输入的是否为正确的 url地址
protected static Boolean IsMatchUrl(String path) { String regExp = String.Empty; regExp = @"^((https|http|ftp|rtsp|mms)?://)" + @"?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@ + @"(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 221.2.162.15 + @"|" // 允许IP和DOMAIN(域名) + @"([0-9a-z_!~*'()-]+\.)*" // 域名- www. + @"([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名 + @"[a-z]{2,6})" // first level domain- .com or .museum + @"(:[0-9]{1,4})?" // 端口- :80 + @"((/?)|" // a slash isn't required if there is no file name + @"(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; regex = new Regex(regExp); return regex.IsMatch(path); }
记录学习点滴...,坚持每天让自己的技能增加1%,默默的坚持下去吧!:-)