I have a membership database from my users.I like to allow them to send mail to admin.However I don't know passwords for their mail addresses.Is there any way to allow this?Here is the code
No need to have credential such as password to send the Mail.
1.) Only you requred is SMTP Server on your Network which is listening & enabled port : 25.
2.) User who is sending mail need to be registered on LDAP or having NT Authentication.
using System.Net.Mail;
using System.Configuration;
public int SendMessage(string subject, string messageBody,string fromAddress, string toAddress)
{
MailMessage message = new MailMessage();
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
message.From = new MailAddress(fromAddress.ToString ());
message.To.Add(new MailAddress(toAddress));
message.Subject = subject;
message.Body = messageBody;
client.Host = "SMTPServerName"; //put your SMTP server address
client.Port = 25; // put your smtp port number
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential("mail id", "password");
client.Send(message); return 1;
}
vikifor
0 Points
24 Posts
Sending mail failed because of unknown NetworkCredential
Aug 06, 2012 07:53 AM|LINK
I have a membership database from my users.I like to allow them to send mail to admin.However I don't know passwords for their mail addresses.Is there any way to allow this?Here is the code
MailMessage msg = new MailMessage("*********@yahoo.com", "***********@gmail.com"); TextBox txtSubject = (TextBox)this.FindControl("txtSubject"); TextBox txtBody = (TextBox)this.FindControl("txtBody"); msg.Subject = txtSubject.Text; msg.Body = txtBody.Text; SmtpClient smtp = new SmtpClient(); smtp.Host = Host; smtp.Port = Convert.ToInt32(Port); smtp.EnableSsl = true; smtp.UseDefaultCredentials = true; smtp.Send(msg);Thanks
email smpt send
Rajesh Sawan...
Participant
1612 Points
246 Posts
Re: Sending mail failed because of unknown NetworkCredential
Aug 06, 2012 08:27 AM|LINK
Hi,
No need to have credential such as password to send the Mail.
1.) Only you requred is SMTP Server on your Network which is listening & enabled port : 25.
2.) User who is sending mail need to be registered on LDAP or having NT Authentication.
All this things are enough.
Below is the Sample code to send the Email.
System.Web.Mail.MailMessage message=new System.Web.Mail.MailMessage();
message.From="from e-mail";
message.To="to e-mail";
message.Subject="Message Subject";
message.Body="Message Body";
System.Web.Mail.SmtpMail.SmtpServer="SMTP Server Address";
System.Web.Mail.SmtpMail.Send(message);
email smpt send net
//Happy Coding
Regards,
RajeshS.
msomar
Participant
843 Points
392 Posts
Re: Sending mail failed because of unknown NetworkCredential
Aug 06, 2012 08:34 AM|LINK
http://forums.asp.net/t/1704109.aspx/3/10?send+email
http://forums.asp.net/t/1751706.aspx/1?how+to+send+email+with+the+recipient+photo+attached+to+it
using System.Net.Mail; using System.Configuration; public int SendMessage(string subject, string messageBody,string fromAddress, string toAddress) { MailMessage message = new MailMessage(); message.IsBodyHtml = true; SmtpClient client = new SmtpClient(); message.From = new MailAddress(fromAddress.ToString ()); message.To.Add(new MailAddress(toAddress)); message.Subject = subject; message.Body = messageBody; client.Host = "SMTPServerName"; //put your SMTP server address client.Port = 25; // put your smtp port number client.UseDefaultCredentials = true; client.Credentials = new System.Net.NetworkCredential("mail id", "password"); client.Send(message); return 1; }email smpt send
Ramesh Chand...
Star
12922 Points
2672 Posts
Re: Sending mail failed because of unknown NetworkCredential
Aug 06, 2012 08:39 AM|LINK
no need to use their credentials, you can use your credientials to send email.
email smpt send
vikifor
0 Points
24 Posts
Re: Sending mail failed because of unknown NetworkCredential
Aug 06, 2012 08:47 AM|LINK
The code is OK, but my problem is that I don't know the password of my users e-mail in this code line
client.Credentials = new System.Net.NetworkCredential("mail id", "password");The mail id is From part am I right?
email smpt send
Ramesh Chand...
Star
12922 Points
2672 Posts
Re: Sending mail failed because of unknown NetworkCredential
Aug 06, 2012 08:48 AM|LINK
You have to use your own credientials.
vikifor
0 Points
24 Posts
Re: Sending mail failed because of unknown NetworkCredential
Aug 06, 2012 08:49 AM|LINK
I got warning that System.Web.Mail.MailMessage is not in use any more.My problem is that I don't know the user email password
in this code line
client.Credentials = new System.Net.NetworkCredential("mail id", "password");Ramesh Chand...
Star
12922 Points
2672 Posts
Re: Sending mail failed because of unknown NetworkCredential
Aug 06, 2012 08:51 AM|LINK
did you try my solution or you are not able to get me. ?
vikifor
0 Points
24 Posts
Re: Sending mail failed because of unknown NetworkCredential
Aug 06, 2012 08:58 AM|LINK
I get you.Maybe I wasn't clear in my explanation.I like users to send mail to me but I don't have the password from their e-mail.
Ramesh Chand...
Star
12922 Points
2672 Posts
Re: Sending mail failed because of unknown NetworkCredential
Aug 06, 2012 09:03 AM|LINK
I got what you are saying. you does have the passoword of user and you want that email shuold be sent to you by that user. right ?
you can't do it. As you don't know the password of the user, you can't send email from their account.
You have to use your own account to send email to you. on the behalf of the user.