用于发送邮件不起作用的简单控制台应用程序 [英] Simple console application for sending mails not working

查看:70
本文介绍了用于发送邮件不起作用的简单控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译一个简单的控制台应用程序来发送邮件,

我的主要想法是安排它到特定时间发送邮件

使用Windows计划任务后来。因此我需要一个exe文件

来完成这项工作。我使用这个命令编译了我的文件Emailtest.cs

line

csc /r:System.Web.dll Emailtest.cs

我得到了一个.exe文件但是当点击它或执行它时我不是接收任何邮件的b $ b。我不知道问题出在哪里

任何人都可以帮帮我

提前致谢


我给我了代码如下


使用System;

使用System.Web.Mail;


公共类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 =这是用于测试自动电子邮件。;

SmtpMail.SmtpServer =" localhost";

SmtpMail.Send(objMail);

Console.Write(发送给John Gera的邮件);


}

catch(例外情况)

{

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);
}
}
}

推荐答案

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" <乔****** @ gmail.com>在消息中写道

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" ;;
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


这篇关于用于发送邮件不起作用的简单控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆