Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SMTP和MailMessage类的输出不明确_C#_Asp.net_Smtp - Fatal编程技术网

C# SMTP和MailMessage类的输出不明确

C# SMTP和MailMessage类的输出不明确,c#,asp.net,smtp,C#,Asp.net,Smtp,收件人收到了邮件,但格式不正确。我正在尝试通过SMTP发送邮件,如下所示: 网络配置: <system.net> <mailSettings> <smtp> <network host="smtp.gmail.com" userName ="UserName" password ="Password" port="587"/> </smtp> </mailS

收件人收到了邮件,但格式不正确。我正在尝试通过SMTP发送邮件,如下所示:

网络配置

<system.net>
<mailSettings>
  <smtp>
    <network 
      host="smtp.gmail.com" 
      userName ="UserName" 
      password ="Password"
       port="587"/>

  </smtp>
</mailSettings>
</system.net>
protected void Button1_Click(object sender, EventArgs e)
{
        MailAddress from = new MailAddress("mahesh@uiti.5gbfree.com");
        MailAddress to = new MailAddress(DestiEmail.Text); //Gmail Email ID
        MailMessage msg = new MailMessage(from, to);
        msg.Subject = "New User Login Information";
        msg.Body = "User:- " + UserName.Text + " " + "New Loging";
        SmtpClient sc = new SmtpClient();
        sc.EnableSsl = true;
        sc.Send(msg);
 }
上述代码传输消息,但格式不正确。我检查了gmail收件箱,发现gmail没有显示发件人地址,而是显示“收件人”地址作为发件人地址。例如,我的发件人地址:
mahesh@uiti.5gbfree.com
地址是:
mwaghela7@gmail.com
但它使用了
mwaghela7@gmail.com
从地址开始

我已经在
maildaddress
中正确地绑定了from和to address的值,并在MailMessages中提供了它的值,如上所述,但不知道为什么它以错误的形式显示


MailMessages类或SMTP中是否存在问题?我需要做什么来修复此问题?

如果可能,我可以通过
mwaghela7@gmail.com
:)我认为带有Gmail的SmtpClient可以从用户处获得
,作为经过身份验证的用户来建立smtp连接。@Damith,如果是这样的话,那么MailAddress和MailMassages类就没有用了,不是吗?我的想法是一些SMTPs(在这个特殊情况下是gmail)可以防止您更改地址,而其他人很容易允许更改。@Lanorkin,您的意思是某个主机不是SMTP wright?@MaheshWagh不,我的意思是SMTP-您用来发送邮件的服务器。通常SMTP知道您的登录名/密码,所以它确实知道您是谁,从而可以防止您在现场进行欺诈