Reputation: 15953
I want to send email using the SMTP client in C#. Currently I am using this code:
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("receiver");
message.Subject = "";
message.From = new System.Net.Mail.MailAddress("sender");
message.Body = "This is a test mail";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.Credentials = new System.Net.NetworkCredential("username", "password");
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Send(message);
But I want to send mail with out using username and password by just providing the sender address. Is this possible in C#? Is this possible with any SMTP server(Not google). I mean login to server anonymously and just provide your mail address.
Upvotes: 0
Views: 3872
Reputation: 101130
The SMTP server in IIS allows this per default if your application is on the same server as IIS.
Upvotes: 2
Reputation: 9653
In the end you'll have to send credentials if the server demands them.
You could send the credentials of the current security context if that's what you're looking for. See: http://msdn.microsoft.com/en-us/library/system.net.credentialcache.defaultnetworkcredentials.aspx.
Upvotes: 0
Reputation: 190907
It depends on your server. In your code you are using Gmail and Gmail requires this.
You can set up your own SMTP server.
Upvotes: 1
Reputation: 120917
No. Gmail does not allow anonymous senders. Thankfully. If it was possible anyone could pretend to send emails from everyone else, rendering gmail as one big spam engine.
Upvotes: 3