开发者

C# - Send e-mail without having to login to server

I have an application that needs to send e-mails. Currently, this is what I am using:

        System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage();
        MyMailMessage.From = new System.Net.Mail.MailAddress(fromemail.Text);
        MyMailMessage.To.Add(toemail.Text);
        My开发者_开发技巧MailMessage.Subject = subject.Text;
        MyMailMessage.Body = body.Text;
        System.Net.Mail.SmtpClient SMTPServer = new System.Net.Mail.SmtpClient("smtp.gmail.com");
        SMTPServer.Port = 587;
        SMTPServer.Credentials = new System.Net.NetworkCredential("email", "password");
        SMTPServer.EnableSsl = true;
        SMTPServer.Send(MyMailMessage);

Is there a simple way to send an e-mail without having to login to a server? Thank you.


GMail's SMTP server always requires authentication. You may need to setup your own server to send email without authentication.


Configure an SMTP server into your local network (behind a firewall to avoid being a spam source) and use it directly. You can create one in IIS.


There are 2 ways to achieve this:

1) Use your local smtp server (e.g. one with IIS on Win2003/2008 server) and write messages to the local pickup queue). This is possible with minimal changes.

2) You need to resolve the target smtp server. For example when you want to send an email to somebody at msn.com, you'll need to get the MX record for msn.com, e.g. something like mx1.msn.com. You can then directly connect to this SMTP server and send your email to the (local) recipient. Note that there are no built-in ways to resolve the MX-host in .NET (in the sense there are no methods on the Dns class to accomplish this) - you need to do it "manually". Also most SMTP hosts will reject connections from home/residential IP addresses.


You need an SMTP server that does not require authentication, however to stop it being a SPAM server, it needs some other kind of protection like a firewall.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜