Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

VB
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..
Posted
Comments
Sergey Alexandrovich Kryukov 14-Jun-15 16:08pm    
This is no less of absurd as asking what's the different between paper, letter and postal stamp.
Please 1) try to ask logically sensible questions, 2) read the documentation.
—SA
atul sharma 5126 16-Jun-15 1:16am    
Thanks for your suggestion Mr. Sergey!

Please 1) Try to invest you time in helping
2) And not pulling down the less knowledgeable ones.
Sergey Alexandrovich Kryukov 16-Jun-15 6:16am    
Aha, it looks like reading the documentation pulls you down? Congratulations!
Thank you for your valuable advice. You really "invest time in helping", not like others.
—SA

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900