6

I am making a simple website. It is hosted on my VPS to which I run IIS 7 and have full access to. DNS is setup and configured but no mail servers or anything are configured.

I want users to be able to send feedback through a very simple form.

I however do not have an SMTP server (that I am aware of).

string from = "";
    string to = "someemails@hotmail.com";
    string subject = "Hi!";
    string body = "How are you?";
    SmtpMail.SmtpServer = "mail.example.com";
    SmtpMail.Send(from, to, subject, body);

I want to send the messages to a free email account but I'm not sure how since I do not have an SMTP server.

Is there some other way I can do it? Or some alternative (like using a free smpt or something)

Thanks

jmasterx
  • 52,639
  • 96
  • 311
  • 557
  • 3
    You could use the SMTP server of your mail provider. (smtp.gmail.com, smtp.live.com or else) – Steve Dec 25 '13 at 21:48
  • Not clear what are you looking for - SMTP server location (off-topic on SO as searching for external tools, but some provided by Steve), way to send mail indirectly (Outlook interop?) or way to configure your own SMTP server (better for http://ServerFault.com) – Alexei Levenkov Dec 25 '13 at 23:14
  • You need to read more on the role of SMTP clients and servers. When you do, you'll realize that you can't do what you're trying to do without one. – james.garriss Dec 25 '13 at 23:19

3 Answers3

5

Sending email directly from your code to the receiving mail server isn't recommended and is like running your own mail server as far as the receiving mail server is concerned. A lot goes into running a mail server properly to ensure reliably delivered email. As an example, one of those things (very important) is having correct reverse dns records (disclosure: documentation link at company I work for).

Instead, you should relay your email through a real email server. You can use the SMTP server of any email address you already have, including gmail.

Use SMTPClient with SMTP Authentication and SSL (if supported).

Code Example:

using System.Net;
using System.Net.Mail;

string fromEmail = "FromYou@gmail.com";
MailMessage mailMessage = new MailMessage(fromEmail, "ToAnyone@example.com", "Subject", "Body");
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(fromEmail, "password");
try {
    smtpClient.Send(mailMessage);
}
catch (Exception ex) {
    //Error
    //Console.WriteLine(ex.Message);
    Response.Write(ex.Message);
}
Nitin Agarwal
  • 3,830
  • 1
  • 21
  • 12
2

As an alternative, in your config file, you could put

<configuration>
  <system.net>
     <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="C:\somedirectory" />
      </smtp>
     </mailSettings>
  </system.net>
</configuration>

This will cause all sent mail to be sent to disk in the specifiedPickupDirectory instead of having to configure the SMTP settings.

shamp00
  • 11,106
  • 4
  • 38
  • 81
0

It is not possible tosend without a smtp server, but you could either use your emailprovider or a free smtp like turbosmtp http://www.serversmtp.com/en/free-smtp-server

Softwarehuset
  • 815
  • 4
  • 10