1

Do I need to set up any mail account or can use my default username and password? What is Credentials? What does that do?

SmtpClient smtpClient = new SmtpClient("mail.iqubekct.in", 25);
smtpClient.Credentials = new System.Net.NetworkCredential("info@MyWebsiteDomainName.com", "myIDPassword");
smtpClient.UseDefaultCredentials = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();

mail.From = new MailAddress("info@MyWebsiteDomainName", "MyWeb Site");
mail.To.Add(new MailAddress("info@MyWebsiteDomainName"));
mail.CC.Add(new MailAddress("MyEmailID@gmail.com"));

smtpClient.Send(mail);
Christos
  • 53,228
  • 8
  • 76
  • 108
Rahul
  • 159
  • 1
  • 9
  • 1
    Have you tried it that way? are you getting any errors. Please indicate if this is working, and if not, what is the issue. – czuroski Sep 18 '14 at 14:10
  • actually I haven't as I don't know what to specify for the credentials. – Rahul Sep 18 '14 at 14:12
  • Specify the email address and password in `NetworkCredential` for the account the mail is going to be sent from – Izzy Sep 18 '14 at 14:17
  • @lzzy u mean the password and the username of my HIOX account??? – Rahul Sep 18 '14 at 14:18

2 Answers2

0

ake a look at this post - https://stackoverflow.com/a/2766967/306894 - I think it may get you what you need.

SmtpClient mailer = new SmtpClient();
mailer.Host = "mail.youroutgoingsmtpserver.com";
mailer.Credentials = new System.Net.NetworkCredential("yourusername", "yourpassword");
Community
  • 1
  • 1
czuroski
  • 4,316
  • 9
  • 50
  • 86
0

if you are running the code from the same domain as the mail server, you do not need credentials, .net will take care of that for you. you only need to specify an existing mailbox for the from field.

if you are running it from a different domain, you need to specify the credentials for that box:

mySmtpClient.Credentials = new System.Net.NetworkCredential("Username","Password");
Banana
  • 7,424
  • 3
  • 22
  • 43