By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,012 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,012 IT Pros & Developers. It's quick & easy.

Simple console application for sending mails not working

P: n/a
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 need an exe file
to make that work. I compiled my file Emailtest.cs using this command
line
csc /r:System.Web.dll Emailtest.cs
and i got an .exe file but when clicking it or executing it i'm not
receiving any mail. I dont know where the problem is
Can anyone help me out please
Thanks in Advance

I'm giving my code below

using System;
using System.Web.Mail;

public class Emailtest
{
public static void Main()
{
try
{
MailMessage objMail = new MailMessage();
objMail.From = "mailfrom";
objMail.To = "ge*******@yahoo.com";
objMail.Subject = "test mail";
objMail.BodyFormat = MailFormat.Html;
objMail.Body = "this is for testing automatic emails.";
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(objMail);
Console.Write("Mail Sent to John Gera");

}
catch (Exception ex)
{
Console.Write(ex.Message);
}
}
}

Nov 17 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
savvy wrote:
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 need an exe file
to make that work. I compiled my file Emailtest.cs using this command
line
csc /r:System.Web.dll Emailtest.cs
and i got an .exe file but when clicking it or executing it i'm not
receiving any mail. I dont know where the problem is


<snip>

Well, when you executed it from the command line, does it show an
exception?

Jon

Nov 17 '05 #2

P: n/a
Hi,
Are you getting any exception?
Do you have configured your local mail server?

Check in the local mailer to see if the mail is in the queue

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"savvy" <jo******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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 need an exe file
to make that work. I compiled my file Emailtest.cs using this command
line
csc /r:System.Web.dll Emailtest.cs
and i got an .exe file but when clicking it or executing it i'm not
receiving any mail. I dont know where the problem is
Can anyone help me out please
Thanks in Advance

I'm giving my code below

using System;
using System.Web.Mail;

public class Emailtest
{
public static void Main()
{
try
{
MailMessage objMail = new MailMessage();
objMail.From = "mailfrom";
objMail.To = "ge*******@yahoo.com";
objMail.Subject = "test mail";
objMail.BodyFormat = MailFormat.Html;
objMail.Body = "this is for testing automatic emails.";
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(objMail);
Console.Write("Mail Sent to John Gera");

}
catch (Exception ex)
{
Console.Write(ex.Message);
}
}
}

Nov 17 '05 #3

P: n/a
Thanks for your time and responses
Its working now
I made a small change in my code .. its

SmtpMail.SmtpServer.Insert( 0, "localhost");

and I'm able to send mails now
Thank you very much once again

Nov 17 '05 #4

P: n/a
Thanks Ignacio Machin for your help and time
Its working now

Nov 17 '05 #5

P: n/a
savvy wrote:
Thanks for your time and responses
Its working now
I made a small change in my code .. its

SmtpMail.SmtpServer.Insert( 0, "localhost");

and I'm able to send mails now


Hmm... that's actually not doing anything at all - it's just fetching
the current value of SmtpServer and calling Insert on it, then throwing
away the result. I very much suspect that if you remove that line of
code, it will still work...

Jon

Nov 17 '05 #6

P: n/a

"savvy" <jo******@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Thanks for your time and responses
Its working now
I made a small change in my code .. its

SmtpMail.SmtpServer.Insert( 0, "localhost");

and I'm able to send mails now
Thank you very much once again


I don't get it, AFAIK there is no Insert method on SmtpServer.

Willy.
Nov 17 '05 #7

P: n/a
Willy Denoyette [MVP] <wi*************@telenet.be> wrote:

"savvy" <jo******@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Thanks for your time and responses
Its working now
I made a small change in my code .. its

SmtpMail.SmtpServer.Insert( 0, "localhost");

and I'm able to send mails now
Thank you very much once again


I don't get it, AFAIK there is no Insert method on SmtpServer.


The SmtpServer property is of type String, however - so it's calling
String.Insert - which is a no-op, as the return value isn't being used.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #8

P: n/a

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Willy Denoyette [MVP] <wi*************@telenet.be> wrote:

"savvy" <jo******@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
> Thanks for your time and responses
> Its working now
> I made a small change in my code .. its
>
> SmtpMail.SmtpServer.Insert( 0, "localhost");
>
> and I'm able to send mails now
> Thank you very much once again


I don't get it, AFAIK there is no Insert method on SmtpServer.


The SmtpServer property is of type String, however - so it's calling
String.Insert - which is a no-op, as the return value isn't being used.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


My bad, I did a simple search on SmtpServer.Insert, obviously without result
as SmtpServer is a property of type string, note that the SmtpMail class is
obsolete in v2.0, suggested replacement is System.Net.Mail.

Willy.
Nov 17 '05 #9

P: n/a
McAfee AV will stop exes from sending mail! Other AV packages also render
your PC so safe as to be unusable, usually without so much as a 'by your
leave'!

"savvy" <jo******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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 need an exe file
to make that work. I compiled my file Emailtest.cs using this command
line
csc /r:System.Web.dll Emailtest.cs
and i got an .exe file but when clicking it or executing it i'm not
receiving any mail. I dont know where the problem is
Can anyone help me out please
Thanks in Advance

I'm giving my code below

using System;
using System.Web.Mail;

public class Emailtest
{
public static void Main()
{
try
{
MailMessage objMail = new MailMessage();
objMail.From = "mailfrom";
objMail.To = "ge*******@yahoo.com";
objMail.Subject = "test mail";
objMail.BodyFormat = MailFormat.Html;
objMail.Body = "this is for testing automatic emails.";
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(objMail);
Console.Write("Mail Sent to John Gera");

}
catch (Exception ex)
{
Console.Write(ex.Message);
}
}
}

Nov 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.