Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
sory but i need user name and password for this
smtp.Credentials = new NetworkCredential("username","password");
where and how can i get that.....

//The code is as follows just explain me one line
//what will be the parameters for this line of code
//where will i get the user name and password for this

// smtp.Credentials = new NetworkCredential("username","password");

 button_click()
{

  MailAddress mailfrom = new MailAddress("sender@gmail.com");
    MailAddress mailto = new MailAddress("receiver@abc.com");
    MailMessage newmsg = new MailMessage(mailfrom, mailto);
 
    newmsg.Subject = "Subject of Email";
    newmsg.Body = "Body(message) of email";
 
    //For File Attachment, more file can also be attached
    Attachment att = new Attachment("C:\\...file path");
    newmsg.Attachments.Add(att);
 
    SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new NetworkCredential("username","password");
    smtp.EnableSsl = true;
    smtp.Send(newmsg);    
}



-------dhanyabaad
Posted
Updated 22-Jul-11 9:36am
v3

The Attachments property is a collection of Attachment objects. Just keep adding them until you're done.
 
Share this answer
 
Comments
Member 8043849 22-Jul-11 15:34pm    
sory but i need user name and password for this

smtp.Credentials = new NetworkCredential("username","password");
Please Try Multiple File Attachment.
Using This Code:
MailMessage newmsg = new MailMessage(mailfrom, mailto);
string[] FileName = new string[] {"File1","File2" };
foreach (string File in FileName)
{
       Attachment atch = new Attachment(File);
       newmsg.Attachments.Add(atch);
}
 
Share this answer
 
Comments
Member 8043849 22-Jul-11 16:12pm    
sory but i need user name and password for this

smtp.Credentials = new NetworkCredential("username","password");
Ask your smtp server administrator (possibly in conjunction with your network administrator) for the account details required.
 
Share this answer
 
Are you serious?

Did you ever think of ASKING THE USER??
 
Share this answer
 
Comments
AspDotNetDev 22-Jul-11 16:41pm    
Most likely, this person is sending an email from a webpage. The sender credentials would be the username/password of an email account the OP wants to use to send emails (note that the username isn't the same as the email address). It's not an unreasonable question.
Dave Kreskowiak 22-Jul-11 18:23pm    
Yes it is. Either he's going to ask the user for the cred's or he ask to have his own account for sending the email or have an account created. No matter what the option, it's just a ridiculous question.
 
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