Hi All,
I trying to send a mail from C# console application.
Please find the my code as below.
This code is working fine with running local smtp server running on my system, I just want to know that, is there anyway to send to mail from default smtp server from IIS server. Like "sendmail" command on Linux.
I trying to send a mail from C# console application.
Please find the my code as below.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mail;
using System.Web.Configuration;
namespace samplemail
{
class Program
{
static void Main(string[] args)
{
try
{
System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage();
mailMsg.From = new System.Net.Mail.MailAddress("from@fromdomain.com"));
mailMsg.To.Add(new System.Net.Mail.MailAddress("to@todomain.com"));
mailMsg.Subject = "Send Using Web Mail";
mailMsg.Body = "This is test mail";
System.Net.Mail.SmtpClient _smtp = new System.Net.Mail.SmtpClient("localhost");
_smtp.EnableSsl = false;
_smtp.Send(mailMsg);
_smtp = null;
}
catch (Exception e)
{
Console.WriteLine("Exception caught in process: {0}", e.ToString());
Console.ReadLine();
}
}
}
}
Comment