问题描述
嗨朋友
以下是我的网站联系我们页面发送电子邮件的代码。
Hi friends
The following is my code for sending email in contact us page of my website.
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress(emailid.Text);
msg.To.Add("[email protected]");
msg.Subject = subject.Text;
msg.Body = txtBody.Text;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "mygmailpassword");
smtp.EnableSsl = true;
smtp.Send(msg);
在我的收件箱[email protected],我刚收到[email protected]的消息。但我想从email.txt(有人输入他们的电子邮件ID)收到邮件。可以改变那个东西。
in my inbox of [email protected], i just received the message from [email protected]. but i want to get mail from email.txt(where somebody enter their email id).how can change that thing.
推荐答案
public static bool SendMail(string From, string To, string Subject, string Body)
{
MailMessage msg = new MailMessage(From, To, Subject, Body);
System.Net.NetworkCredential acc = new System.Net.NetworkCredential("Your Email", "Your Password");
// server name can be find your mail servers option menu
SmtpClient srv = new SmtpClient("Your SMTP Server");
// use this true when your code in a asp.net site and from email is your websites domain email
srv.UseDefaultCredentials = true;
srv.Credentials = acc;
msg.Priority = MailPriority.High;
msg.IsBodyHtml = true;
try
{
srv.Send(msg);
return true;
}
catch
{
return false;
}
}
这里,
您的电子邮件=电子邮件地址,这是使用您的SMPT服务器创建的。例如[email protected]
您的密码=您的电子邮件密码。
您的SMTP服务器=您域名的SMPT服务器。像mail.test.com,这里是www.test.com你的域名。
Here,
Your Email= An email address, which was created using your SMPT server. Like "[email protected]"
Your Password= Password of your email.
Your SMTP Server= A SMPT server of your domain. Like "mail.test.com", here "www.test.com" your domain.
这篇关于发送电子邮件与我们联系表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!