Reputation: 69
I may be Wrong but I am stuck in an issue... I want to send the email to the user using ASP.net without having the password HERE is my code
But I do not have the password .How can I send email to the user without having their password.
protected void submit_Click(object sender, Event Args e)
{
MailMessage mail = new MailMessage();
mail.To.Add(txtTo. Text);
mail.From = new Mail Address(txt_from.Text);
mail.Subject = txtSubject. Text;
mail.Body = txtBody.Text;
mail.IsBodyHtml = true;
if (fileUpload1.HasFile)
{
mail.Attachments.Add(new Attachment(fileUpload1.PostedFile.InputStream, fileUpload1.FileName));
}
SmtpClient smtp = new SmtpClient();
smtp.Host = "mysmtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential("email", "password");
//Or your Smtp Email ID and Password
smtp.EnableSsl = true;
smtp.Send(mail);
}
Upvotes: 0
Views: 1598
Reputation: 185
You don't need their password to send email. You need password to your stmp server. You have to sing in to it to send any mail. Try to create an email address for test puproses and use it credentials to send email.
There is part which you should fix for gmail stmp server:
smtp.Host = "smtp.gmail.com";
stmp.Port = 465;
stmp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential
("[email protected]", "exampleGmailPassword");
Upvotes: 2