Reputation: 2369
I have a C# Web App (Using ASP.NET 2.0) and I want to use it to send email. I have researched about this online, but I've only gotten more confused. I have learned some basics, but it isn't getting me anywhere. Here's what I have so far:
MailMessage message = new MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text);
SmtpClient emailClient = new SmtpClient(txtSMTPServer.Text);
emailClient.Send(message);
All the controls prefixed txt are text boxes. I got part of this from an onlin tutorial, but it doesn't work because I'm not sure what I should put in the SMTP server Textbox. Can anyone help me? Thanks
Upvotes: 1
Views: 2154
Reputation: 9119
It depends on where you run your project. If it is your localhost, just put localhost or you wanna publish it on a hosted web site, you should put the mail server name that is given by the company or write local host again. I think it works. For port number you may use 25.
Upvotes: 1
Reputation: 52241
put this in your web.config, SMTP outgoing server setting
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network defaultCredentials="false" port="25" host="mail.abc.com" userName="[email protected]" password="abc123"/>
</smtp>
</mailSettings>
</system.net>
and make an object of an smtp like, it will take SMTP setting automatically
SmtpClient emailClient = new SmtpClient();
check this thread as well.Sending Email in ASP.NET 2.0
Upvotes: 2
Reputation: 9146
This refers to the address of the SMTP server (the outgoing mail) that will process the message. If you have Outlook or Thunderbird installed, open up your email account settings and take a look in their for your SMTP details.
Upvotes: 1
Reputation: 1500515
You need to put in your local SMTP server - probably the one in the same network as your web server. You may even be able to just use "localhost" if the IIS you're running on sends mail as well. Alternatively, are you running Exchange somewhere in the network?
Upvotes: 4