473,386 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.
Expand|Select|Wrap|Line Numbers
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Web.Mail;
  7. using System.Web.Configuration;
  8.  
  9. namespace samplemail
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             try
  16.             {
  17.                 System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage();
  18.                 mailMsg.From = new System.Net.Mail.MailAddress("from@fromdomain.com"));
  19.                 mailMsg.To.Add(new System.Net.Mail.MailAddress("to@todomain.com"));
  20.                 mailMsg.Subject = "Send Using Web Mail";
  21.                 mailMsg.Body = "This is test mail";
  22.                 System.Net.Mail.SmtpClient _smtp = new System.Net.Mail.SmtpClient("localhost");
  23.                 _smtp.EnableSsl = false;
  24.                 _smtp.Send(mailMsg);
  25.                 _smtp = null;
  26.             }
  27.             catch (Exception e)
  28.             {
  29.                 Console.WriteLine("Exception caught in process: {0}", e.ToString());
  30.                 Console.ReadLine();
  31.             }
  32.  
  33.         }
  34.  
  35.     }
  36. }
  37.  
  38.  
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.
Aug 9 '10 #1
2 10184
johny10151981
1,059 1GB
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?
Aug 9 '10 #2
drhowarddrfine
7,435 Expert 4TB
This is not a HTML/CSS question.
Aug 9 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: erdem kemer | last post by:
i cant send mail to yahoo mail or hotmail while i can send my other mail accounts (pop3) is it becouse yahoo and hotmail is web-based mail here is the code MailMessage mailMsg = new...
1
by: jam | last post by:
Dear All, I am writing a console and it send a email out when it hits error it calls this static void SendErrorEmail(string error) { System.Web.Mail.MailMessage mail = new...
9
by: savvy | last post by:
i'm trying to compile a simple console application for sending a mail, my main idea is to schedule it to a particular time for sending mails using the windows schedular task lateron. Therefore i...
5
by: SatishPasala | last post by:
hi This is a very active group. Anyways I am trying to add Mailing functionality to C# Console Application. How do I get started with here... (I used to use System.Web.Mail in ASP.NET...
2
by: Ryan | last post by:
Hi, I receive an access denied error (see below) when attempting to send an email with BodyFormat=MailFormat.Html from an asp.net page. Exactly the same code works fine in a console...
0
by: Hugh Van | last post by:
Hi all, I'm trying to use .Net.Mail to send email in my program but somehow it always throws me error. I have checked everything in the configuration: username, password, smtpserver, smtp...
1
by: Vijay | last post by:
Hi, I have a problem to send Mail in ASP. I am using CDO for sending mail. My Server configuration are : Windows Server 2003 Stadndard Edition with R2, Service Pack 2, Microsoft Management...
6
by: dolulob | last post by:
Hi, I'm trying to communicate with a console application through a c# program. the console application is micq a console based ICQ client. I want to be able to send an receive messages through...
1
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i have a console application that uses the console to display message status of my process. what's the best way (low impact) to get the messages as they are now into an email? thanks,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.