如何在asp.net中成功注册后发送电子邮件 [英] how to send email after successfully registered in asp.net
本文介绍了如何在asp.net中成功注册后发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是代码: -
this is code :-
try
{
MailMessage mailmsg = new MailMessage();
SmtpClient smp = new SmtpClient("smtp.gmail.com");
mailmsg.From = new MailAddress("[EMAIL_Removed]@gmail.com");
string to = "[EMAIL_Removed]@gmail.com";
string sub = "Data Work";
string mes = System.DateTime.Now.ToString("dd/MM/yyyy") + "Sending mail to from sender User Name:" + txtname + " Email:" + txtemail.Text + " Moblie No:" + txtmobile.Text + " Message: " + txtmsgg.Text + " Organization=" + txtorganization.Text + " Website=" + txtwebsit.Text + " project=" + ddrproject.SelectedValue + " TimeLine=" + ddrtimeline.SelectedValue + " Budget="+ddrbught.SelectedValue+"";
mailmsg.To.Add(to);
mailmsg.Subject = sub;
mailmsg.Body = mes;
smp.Port = 587;
smp.Credentials = new System.Net.NetworkCredential("[EMAIL_Removed]@gmail.com", "example");
smp.EnableSsl = true;
mailmsg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
smp.Send(mailmsg);
lblmss.Text = " Thanks for contact us";
}
catch (Exception)
{
}
但是此代码无法使用
请在成功注册后帮我发送电子邮件?
谢谢
更正格式和/或语法问题。
添加预
标签。
[/ edit]
推荐答案
请参阅我之前的回答从asp.net发送电子邮件到gmail [ ^ ]。
你会的获得完整的工作代码。
如果您仍然遇到任何问题,请告诉我。在这种情况下,也要发布异常消息。
Refer my previous answer sending email to gmail from asp.net[^].
You will get the full working code.
Let me know if you are still getting any issues. In that case, post the exception message as well.
尝试这个..
protected void btnSend_Click(object sender, EventArgs e)
{
尝试
{
System.Net.Mail.MailMessage mailMessage = new System。 Net.Mail.MailMessage(txtMailFrom.Text,txtMailTo.Text,txtSubject.Text,txtBody.Text);
/ *如果添加CC和BCC
MailAddress bcc = new MailAddress(txtBcc.Text);
MailAddress cc = new MailAddress(txtCC.Text);
mailMessage.Bcc.Add(bcc);
mailMessage.CC.Add(cc);
* /
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Send(mailMessage);
Response.Write(< script> alert('Mail Sent')< / script>);
}
catch(例外情况)
{
抛出ex;
}
}
在配置文件中添加这个
try this one..
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage(txtMailFrom.Text, txtMailTo.Text, txtSubject.Text, txtBody.Text);
/* In case of adding CC and BCC
MailAddress bcc = new MailAddress(txtBcc.Text);
MailAddress cc = new MailAddress(txtCC.Text);
mailMessage.Bcc.Add(bcc);
mailMessage.CC.Add(cc);
*/
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Send(mailMessage);
Response.Write("<script>alert('Mail Sent')</script>");
}
catch (Exception ex)
{
throw ex;
}
}
And in the Configuration file add this
<system.net>
<mailSettings>
<smtp>
<network host="" port="" userName="" password=""/>
</smtp>
</mailSettings>
</system.net>
Use ‘using System.Net.Mail;’
/// <summary>
/// Method to send mail.
/// </summary>
/// <param name="mailTo">Recipient's Email-Id</param>
/// <param name="User">Recipient's User Name </param>
/// <returns>true if mail sent; otherwise, false.</returns>
private Boolean SendMail(String mailTo, String User)
{
Boolean sendMailResult;
try
{
SmtpClient smtpServer = new SmtpClient();
smtpServer.Credentials = new System.Net.NetworkCredential("", ""); //Add sender’s Email-Id and Password here.
smtpServer.Port = 25;
smtpServer.Host = "smtp.gmail.com";
MailMessage alertMail = new MailMessage();
alertMail.From = new MailAddress(""); //Add Sender’s Email-Id.
alertMail.Subject = "Alert Mail";
alertMail.To.Add(mailTo);
alertMail.Body = "Dear " + User + "," + Environment.NewLine + " Please Check";
smtpServer.Send(alertMail);
sendMailResult = true;
return sendMailResult;
}
catch (Exception ex)
{
string exceptionMessage=ex.Message;
sendMailResult = false;
return sendMailResult;
}
finally
{
}
}
这篇关于如何在asp.net中成功注册后发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文