smtpclient.credentials和mailmessage.from之间的区别 [英] Difference between smtpclient.credentials and mailmessage.from

查看:127
本文介绍了smtpclient.credentials和mailmessage.from之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我可以从网页发送包含以下代码的测试电子邮件。但是在客户端实现如何使用凭证属性时我需要更清晰..

目前我在smtpclient.credentials和mailmessage.from属性中使用相同的gmail id



Hi All,

I am able to send a test email with following code from a webpage. But I need more clarity while implementing on client side on how to use the credentials property..
Currently I am using same gmail id in smtpclient.credentials and mailmessage.from property

Dim Smtp_Server As New SmtpClient
      Dim e_mail As New MailMessage()
      Smtp_Server.UseDefaultCredentials = False
      Smtp_Server.Credentials = New Net.NetworkCredential("abc@gmail.com", "123")
      Smtp_Server.Port = 587
      Smtp_Server.EnableSsl = True
      Smtp_Server.Host = "smtp.gmail.com"

      e_mail = New MailMessage()
      e_mail.From = New MailAddress(txtFrom.Text)
      e_mail.To.Add(txtTo.Text)
      'e_mail.CC.Add(txtTo.Text)
      e_mail.Subject = "Email Sending"

      link = Server.HtmlEncode("www.google.co.in")
      e_mail.IsBodyHtml = True
      e_mail.Body = txtMessage.Text & " " & "<a href='" & link & "'>Click here</a>"

      Dim attachfile As New Attachment("H:\test.xlsx")
      e_mail.Attachments.Add(attachfile)


      Smtp_Server.Send(e_mail)





谢谢..



Thanks..

推荐答案

简单, 凭据 [ ^ ]属性 SmtpClient [ ^ ]对象用于SMTP服务器上的身份验证过程,它是您的用户名/客户端,服务器或其他应用程序使用的密码,您可以使用该密码对自己进行身份验证以使用该服务。



来自 [ ^ ] MailMessage [ ^ ]对象,它是您在电子邮件发件人字段中看到的字段。它们(并且它们可以)是不同的,但有时SMTP服务器会通知收件人该电子邮件尚未通过发件人地址发送。



请阅读附加的MSDN资源文件,他们会更清楚地说明要求和字段。
Simple, the Credentials[^] property of the SmtpClient[^] object is used for authentication process on the SMTP server, it is your username/password used by the SMTP client, server or other application using which you can authenticate yourself to use the service.

The From[^] field in the MailMessage[^] object is used in your email message, it is the field that you see in the Email messages' From field. They are (and they can be) different, but sometimes the SMTP server would notify the recipient that the email has not been sent by the From address.

Please read the attached MSDN documentations for the resources, they would clarify the requirement and fields a little bit more.


这篇关于smtpclient.credentials和mailmessage.from之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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