to send a mail from c# console application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sridhard2406
    New Member
    • Dec 2007
    • 52

    to send a mail from c# console application

    Hi All,

    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();
                }
    
            }
    
        }
    }
    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.
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    As Far I have understood the protocol. SMTP server installed in your local machine will send the mail to the desired client.

    Why dont you try to mail using your local SMTP Server?

    Comment

    • drhowarddrfine
      Recognized Expert Expert
      • Sep 2006
      • 7434

      #3
      This is not a HTML/CSS question.

      Comment

      Working...