发送邮件有访客评论的问题 [英] Problem in Sending Mail Having Visitor Comments

查看:91
本文介绍了发送邮件有访客评论的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有



我想创建一个访问者向网站管理员发送评论的页面。但使用以下代码将邮件发送给发件人而不是站点管理员。请问我在这里犯了什么错误。我的代码在这里。





public static string SendMail(String to,String subject,String body,Boolean isBodyHtml,MailPriority mailPriority)

{

尝试

{

//配置邮件客户端(可能需要额外的

//经过身份验证的SMTP服务器的代码)

SmtpClient mailClient = new SmtpClient(smtp.gmail.com,587);



//设置网络凭证

mailClient.Credentials = new NetworkCredential(mywebadmin@gmail.com,myadminpassword);





//启用ssl

mailClient.EnableSsl = true;



//创建邮件消息(来自,to,subject,body)

MailMessage mailMessage = new MailMessage();

mailMessage.From = new MailAddress(mywebadmin@gamil.com);

mailMessage.To.Add(to);



mailMessage.Subject = subject;

mailMessage.Body = body;

mailMessage.IsBodyHtml = isBodyHtml;

mailMessage.Priority = mailPriority;



//发送邮件

mailClient.Send(mailMessage);



返回消息已成功发送;

}

catch(例外情况)

{

返回ex.Message;

}













}



protected void btnSendmail_Click(object sender, EventArgs e)

{

string s = SendMail(txtSender.Text,txtSubj.Text,txtMessage.Text,true,mailPriority);

lblResponse.Text = s;



}







public MailPriority mailPriority {get;组; }

}

解决方案

很难说,因为To地址被设置为方法之外的值并作为a参数...但是猜测一下,你要做的是在邮件正文中包含txtSender.Text值,并将To地址设置为网络管理员。



但我不会。我将它保存在数据库中,然后让管理员查看一个消息列表 - 为什么要发送一封需要特定地址和身份验证的电子邮件,以便将其保存到数据库并拥有可以访问它的授权列表?

Dear All

I want to crate a page on which the visitor send his comments to the website admin. but with the following code the mail is sent to the sender instead of the site admin. plz identify what mistake I am doing here. my code is here.


public static string SendMail(String to, String subject, String body, Boolean isBodyHtml, MailPriority mailPriority)
{
try
{
// Configure mail client (may need additional
// code for authenticated SMTP servers)
SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587);

// set the network credentials
mailClient.Credentials = new NetworkCredential("mywebadmin@gmail.com", "myadminpassword");


//enable ssl
mailClient.EnableSsl = true;

// Create the mail message (from, to, subject, body)
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("mywebadmin@gamil.com");
mailMessage.To.Add(to);

mailMessage.Subject = subject;
mailMessage.Body = body;
mailMessage.IsBodyHtml = isBodyHtml;
mailMessage.Priority = mailPriority;

// send the mail
mailClient.Send(mailMessage);

return "Message have been sent successfully";
}
catch (Exception ex)
{
return ex.Message;
}






}

protected void btnSendmail_Click(object sender, EventArgs e)
{
string s= SendMail(txtSender.Text,txtSubj.Text,txtMessage.Text,true,mailPriority);
lblResponse.Text = s;

}



public MailPriority mailPriority { get; set; }
}

解决方案

Difficult to tell, since the "To" address is set to a value outside the method and passed through as a parameter...but at a guess, what you want to do is include the txtSender.Text value in you message body, and set the To address to the web admin.

But I wouldn't. I'd save it in a DB and let the Admin view a list of messages - why send an email which requires an specific address and authentication when you could save it to a DB and have a authorization list for who can access it?


这篇关于发送邮件有访客评论的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆