SMTP server Configuration [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this questionI ha开发者_高级运维ve Windows XP and configured SMTP server in my IIS. Specified AllUnAssigned
in IP address of general tab and specified 127.0.0.1
in connection under Access tab.
Now I tried sending mails using my local SMTP server using the following code,
MailMessage amessage = new MailMessage();
amessage.To.Add(new MailAddress("xxx@gmail.com"));
amessage.From = new MailAddress("yyy@gmail.com");
amessage.Subject = "TestMail";
amessage.Body = "This is a testmail";
SmtpClient clienta = new SmtpClient("localhost");
clienta.Timeout = 500;
clienta.Credentials = CredentialCache.DefaultNetworkCredentials;
try
{
clienta.Send(amessage);
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.ReadLine();
}
Console.ReadLine();
I don't get any error in executing the above code but no mails were sent/received. When I checked in the Inetpub I find the below file:
From: postmaster@munged To: yyy@gmail.com Date: Tue, 26 Apr 2011 11:07:22 +0530 MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status; boundary="9B095B5ADSN=_01CC03D260FE2C6C00000003munged?xxx" Message-ID: Subject: Delivery Status Notification (Failure)This is a MIME-formatted message.
Portions of this message may be unreadable without a MIME-capable mail program.--9B095B5ADSN=_01CC03D260FE2C6C00000003munged?munged Content-Type: text/plain; charset=unicode-1-1-utf-7
This is an automatically generated Delivery Status Notification.
Delivery to the following recipients failed.
xxx@gmail.com
--9B095B5ADSN=_01CC03D260FE2C6C00000003munged?munged Content-Type: message/delivery-status
Reporting-MTA: dns;munged Received-From-MTA: dns;munged Arrival-Date: Tue, 26 Apr 2011 11:07:16 +0530
Final-Recipient: rfc822;xxx@gmail.com
Action: failed Status: 5.0.0 Diagnostic-Code: smtp;550-5.7.1 [122.178.191.78] The IP you're using to send mail is not authorized to 550-5.7.1 send email directly to our servers. Please use the SMTP relay at your 550-5.7.1 service provider instead. Learn more at 550 5.7.1 http://mail.google.com/support/bin/answer.py?answer=10336 m9si19863225wfl.114--9B095B5ADSN=_01CC03D260FE2C6C00000003munged?munged Content-Type: message/rfc822
Received: from munged
([127.0.0.1]) by munged with Microsoft SMTPSVC(6.0.2600.2180); Tue, 26 Apr 2011 11:07:16 +0530 MIME-Version: 1.0 From: yyy@gmail.com To: xxx@gmail.com Date: 26 Apr 2011 11:07:16 +0530 Subject: TestMail Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Return-Path: munged@gmail.com Message-ID: X-OriginalArrivalTime: 26 Apr 2011 05:37:16.0515 (UTC) FILETIME=[009D2330:01CC03D4]This is a testmail
--9B095B5ADSN=_01CC03D260FE2C6C00000003munged?munged--
Can anyone please help me on this?
Here's the important part of the error message:
Diagnostic-Code: smtp;550-5.7.1 [122.178.191.78] The IP you're using to send mail is not authorized to 550-5.7.1 send email directly to our servers. Please use the SMTP relay at your 550-5.7.1 service provider instead.
To solve this, you'll need to setup an SMTP relay to send to your ISP's email servers. They'll send to Google for you.
For clarity:
- This is NOT an application/code/C# problem, but an IIS problem.
- Google will NOT accept SMTP connections from random nodes on the internet. That means: YOUR Windows XP SMTP server will not have direct sending ability.
- You MUST send to a known good whitelisted SMTP host.
- Your best option is to configure IIS to act as a relay to a known good SMTP server.
- Your best bet for a known good SMTP server is your ISP's. This is likely
smtp.yourISP.com
. - This tutorial's Steps 2 & 3 will help you achieve this. Your 'smart host' will be your ISP's SMTP server DNS name or IP address.
I think that if you want to send emails through gmail from your PC, you should encrypt your data with SSL. You have to options here:
- use specific asp functions
- use a software like stunnel (it is not so difficult to configure)
You can solve this using one of the following two ways
Option 1. Change '127.0.01' to 'localhost' in connection under Access tab.
Option 2. Change the code used to connect using '127.0.01' instead of localhost.
SmtpClient clienta = new SmtpClient("127.0.01");
精彩评论