且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用于发送邮件不起作用的简单控制台应用程序

更新时间:2023-02-19 19:17:20

savvy写道:
我正在尝试编译一个简单的控制台应用程序来发送邮件,
我的主要想法是安排它到特定时间发送邮件
使用Windows计划任务。因此我需要一个exe文件来完成这项工作。我使用这个命令编译我的文件Emailtest.cs

csc /r:System.Web.dll Emailtest.cs
我得到了一个.exe文件,但点击它或执行它我我没有收到任何邮件。我不知道问题出在哪里
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>


好​​吧,当你从命令行执行它时,是否显示

例外情况?


Jon



<snip>

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

Jon




您是否收到任何例外情况?

您是否配置了本地邮件服务器?


在本地邮件中查看是否有邮件在队列中


欢呼,

-

Ignacio Machin,

ignacio.machin AT dot.state.fl.us

佛罗里达州交通部


" savvy" &LT;乔****** @ gmail.com&GT;在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...
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...
我正在尝试编译一个简单的控制台应用程序来发送邮件,我的主要想法是安排它到特定时间发送邮件
使用Windows计划任务。因此我需要一个exe文件来完成这项工作。我使用这个命令编译我的文件Emailtest.cs

csc /r:System.Web.dll Emailtest.cs
我得到了一个.exe文件,但点击它或执行它我我没有收到任何邮件。我不知道问题出在哪里
任何人都可以帮助我
在此先感谢

我在下面给我的代码

使用系统;
使用System.Web.Mail;

公共类Emailtest
{
public static void Main()
{
尝试
{
MailMessage objMail = new MailMessage();
objMail.From =" mailfrom&quot ;;
objMail.To =" ge ******* @ yahoo.com" ;;
objMail.Subject =" test mail";
objMail.BodyFormat = MailFormat.Html;
objMail.Body ="这是用于测试自动电子邮件。;

SmtpMail.SmtpServer =" localhost";
SmtpMail.Send(objMail);
Console.Write(发送给John Gera的邮件);

}
catch(Exception ex)
{
Console.Write(ex.Message);
}
}
}
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);
}
}
}



感谢您的时间和回复

现在正在工作

我的代码做了一些小改动..它的


SmtpMail.SmtpServer.Insert(0,localhost);


我能够发送邮件现在

再次非常感谢

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