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 = "[email protected]";
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
Send Outlook Emails using C++Create an object of SmtpClient. Set host, username, password, and port number. Set security options. Send email using SmtpClient->Send() method.
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 = "[email protected]";
MailMessage mailMessage = new MailMessage(fromEmail, "[email protected]", "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);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With