在asp.net中发送电子邮件发送密码,而不是电子邮件

问题描述:

我想用户已经注册成功后发送电子邮件。但它发送密码FROM部分,而不是发送电子邮件一样abc@gmail.com这里发送1234kjfh。什么我在这里丢失?

I am trying to send email after user has been registered successfully. but it sends password in FROM section instead of sending email like abc@gmail.com here it sends 1234kjfh. what am I missing here?

string name=txtfirstname.Text;
string fileName = Server.MapPath("~/App_Data/TextFile.txt");
string mailBody = File.ReadAllText(fileName);
mailBody = mailBody.Replace("##Name##", txtfirstname.Text);
mailBody = mailBody.Replace("##Email##", email);
mailBody = mailBody.Replace("##Phone##", txtphone.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Re: Activate your account for AIS FORUM";
myMessage.Body = mailBody;
myMessage.From = new MailAddress("abc@gmail.com", "1234kjfh");
myMessage.To.Add(new MailAddress(txtemail.Text, email));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.EnableSsl = true;  
mySmtpClient.Send(myMessage);

PLZ帮助!

您在这里的东西

新的MailAddress(地址,显示名)

new MailAddress(address, displayName)

所以,你必须添加显示名称为1234kjfh

so, you have added display name as "1234kjfh"

更新您的code如下。

Update your code as follow.

string name=txtfirstname.Text;
        string fileName = Server.MapPath("~/App_Data/TextFile.txt");
        string mailBody = File.ReadAllText(fileName);
        mailBody = mailBody.Replace("##Name##", txtfirstname.Text);
        mailBody = mailBody.Replace("##Email##", email);
        mailBody = mailBody.Replace("##Phone##", txtphone.Text);
        MailMessage myMessage = new MailMessage();
        myMessage.Subject = "Re: Activate your account for AIS FORUM";
        myMessage.Body = mailBody;
        myMessage.From = new MailAddress("abc@gmail.com", "abc@gmail.com");
        myMessage.To.Add(new MailAddress(txtemail.Text, email));
        SmtpClient mySmtpClient = new SmtpClient();
        mySmtpClient.EnableSsl = true;  
        mySmtpClient.Send(myMessage);

希望这有助于。