我需要使用网址发送邮件。
例如 我的网址如下
www.site.com/employee.aspx?EmpCode=12
在employee.aspx中,我从查询字符串获取EmpCode,并使用listview控件从db获取员工配置文件。
我需要将此 www.site.com/employee.aspx?EmpCode=12 网址数据作为电子邮件正文发送。
public static void sendmail(String url,String to,String subject)
{
string from = WebConfigurationManager.AppSettings["fromemail"];
string password = WebConfigurationManager.AppSettings["emailpassword"];
MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from, "EMP PROFILE", System.Text.Encoding.UTF8);
mail.Subject = subject;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = GetPage(url);
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(from, password);
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
try
{
client.Send(mail);
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
}
}
这里我使用webrequest从url读取数据,如下所示
protected static string GetPage(string url)
{
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
StreamReader sr = new StreamReader(objRequest.GetResponse().GetResponseStream());
string result = sr.ReadToEnd();
sr.Close();
return result;
}
但是它显示了像
这样的错误Server Error in '/' Application.
远程服务器返回错误:(500)内部服务器错误。
我需要将员工资料发送到电子邮件。如何解决它