Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have 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");
Related
I've been stuck with this issue for a long time now.
My application can send email without problem from my local and another server but there's this one server where it always fails with this error:
System.IO.IOException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Sample Code:
public static void SendEmail(EmailCreateViewModel viewModel)
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Sender Name", "test#senderemail.com"));
message.To.Add(new MailboxAddress("Recipient Name", "test#recipientemail.com"));
message.Subject = viewModel.Subject;
message.Body = new TextPart("plain") { Text = viewModel.TextBody };
using (var client = new SmtpClient(new ProtocolLogger("C:\\smtp.log")))
{
try
{
if(viewModel.BypassServerCertificateValidationCallback)
client.ServerCertificateValidationCallback = (sender, certificate, certChainType, errors) => true;
client.SslProtocols = System.Security.Authentication.SslProtocols.Tls | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls12;
client.Connect("smtp.office365.com", 587, SecureSocketOptions.StartTls);
client.Authenticate(viewModel.User, viewModel.Password);
client.Send(message);
client.Disconnect(true);
}
catch (Exception ep)
{
Log("failed to send email with the following error:");
Log(ep.ToString());
}
}
}
smtp.log:
Connected to smtp://smtp.office365.com:587/?starttls=always
S: 220 SI2PR02CA0002.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 16 Jun 2022 03:02:14 +0000
C: EHLO <Insert Server Name>
S: 250-SI2PR02CA0002.outlook.office365.com Hello [<Insert Server IP>]
S: 250-SIZE 157286400
S: 250-PIPELINING
S: 250-DSN
S: 250-ENHANCEDSTATUSCODES
S: 250-STARTTLS
S: 250-8BITMIME
S: 250-BINARYMIME
S: 250-CHUNKING
S: 250 SMTPUTF8
C: STARTTLS
S: 220 2.0.0 SMTP server ready
C: EHLO <Insert Server Name>
S: 250-SI2PR02CA0002.outlook.office365.com Hello [<Insert Server IP>]
S: 250-SIZE 157286400
S: 250-PIPELINING
S: 250-DSN
S: 250-ENHANCEDSTATUSCODES
S: 250-AUTH LOGIN XOAUTH2
S: 250-8BITMIME
S: 250-BINARYMIME
S: 250-CHUNKING
S: 250 SMTPUTF8
C: AUTH LOGIN
It feels like I've tried everything and don't know what else to do and the exception itself doesn't say much. I've also tried turning off the firewall and windows defender but it still fails.
To isolate the server, I've been able to send an email from the problematic server via PowerShell with similar settings (same server, port and TLS).
I hope someone can shed some light here or at least give some fresh perspective on this issue. Thanks!
In the end, we weren't able to fix the code itself. After multiple trial and errors, we tried sending the email from a .NET Core console program using the exact code. To our surprise, it worked.
What we ended up doing is convert the old .NET Framework 4.5.2 Service to the latest .NET 6 Worker Service. Tested it again in the problematic server and everything is working fine.
Our hunch is for some reason, the old libraries of .NET Framework was deemed unsecure by the SMTP server (or along the way to the SMTP server) and rejects the connection.
I have strictly followed this tutorial in order to configure SMTP server on Windows Server 2012 R2 by usng IIS 6. In fact, if I create a correct formatted file email.txt inside
C:\inetpub\mailroot\Pickup
with From, To and Subject fields, it is dispatched immediately to the destination email address with the correct sender.
Then, I have a framework generating my ASP NET C# web application ad when it tried to send an email with:
IDMailer v_M1 = null;
v_M1 = (IDMailer)new IDMailer();
v_M1.FromAddress = (new IDVariant("allegretti#er-go.it")).stringValue();
v_M1.AddToAddress((new IDVariant("lorenzo.vinci#conservice.it")).stringValue());
v_M1.Subject = (new IDVariant("prova")).stringValue();
v_M1.HTMLBody = (new IDVariant("<b>ciao!</b>")).stringValue();
try
{
v_M1.SendMail();
}
catch (Exception e3)
{
MainFrm.set_AlertMessage(new IDVariant(e3.Message));
}
then I have an error in sending the email which fails. I have tried also both the following settings in the application pool of my web application:
and they both fail with these error messages:
Thursday, October 6, 2016 - 5:38:09 PM
Failure sending mail.
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at com.progamma.IDMailer.SendMail()
DTT_LEVEL=5
DTT_MSGLEVEL=3
DTT_LEVEL=5
DTT_MSGLEVEL=3
Failure sending mail.
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at com.progamma.IDMailer.SendMail()
The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available
at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
at System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage message)
at System.Web.Mail.SmtpMail.Send(MailMessage message)
at com.progamma.IDMailer.SendMailSSL()
--------------------------------------------------------------------
Thursday, October 6, 2016 - 5:38:25 PM
Failure sending mail.
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at com.progamma.IDMailer.SendMail()
I have no idea why this happens but I really need to correctly set up a SMTP server in our Windows Server. I had tried to use Google smtp server as realy and it was ok but it did not allow us to set an arbitrary sender email address but only the one of the account used to connect to gmail smtp server. That's why I need my SMTP server because sender anddress will vary according to the user logging into the web application.
How can I solve this?
Maybe does this happen because the web applicaion is installed inside drive D (which has its own pickup emailroot directories) instead of C drive?
I am trying to get WebMatrix running on a local server (simply for testing within our intranet), but it is having trouble sending mail where it never did before on my local (work) machine.
I am getting a simple, the operation has timed out message. The account for this is setup through gmail, so I wouldn't think that there would be too many problems, but as I have never set up WebMatrix on a server before, I don't really know how to attack this issue.
When I had the Email working in construction of this website, I used these settings and everything worked fine:
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
Then when I ran it with these settings on the server I got this error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first.
With that, we tried to enable SSL, but get a simple response timed out request after that (using these settings):
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.SmtpPort = 465;
WebMail.EnableSsl = true;
The "Username" and "From" fields are set the same (name#somecity.net) this is an example of our email that is managed by gmail. Also the password is set and correct.
Am I chasing the wrong thing here, by looking into SSL?
You'll have to forgive me in that I have never implemented SSL before. I know what SSL is, but I have never set it up before, so I apologize if I am a kind of a noob when it comes to setting this up.
Also, just so you know for sure, the server error does, in fact, error on the WebMail.Send method.
You should change your SMTP port for the Gmail one. Right now, gmail is working with 587 instead of 465.
You can check it using telnet smtp.gmail.com 587. Then you should get something like this:
220 test.auto.mySMTPserver.com ESMTP Service (Lotus Domino Release 8.5.3FP2 HF95) ready at Tue, 30 Oct 2012 08:27:31 -0700
Your new code:
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.SmtpPort = 587;
WebMail.EnableSsl = true;
And that's it.
I would say that the message tells you you are not authenticated, so you are likely to need to send a username / password for a valid user on the server. See this question for an example of authenticating to a mail server to send.
I know it is possible to send an email with a fake address to impersonate someone else. I seen automated emails coming from my friend email address that he sent to me but did not write himself.
I know email servers ask the email provider if they really sent the message and if it is no it tends to go into spam or is marked untrusted. How do i access this data in my app? I havent chosen an imap library and thats because i dont know which may support this.
This functionality is not supported by imap.
Some servers store information like this in the header of the mail (like spamassassin info or SPF checks) so that is available with any imap library but depends highly on the mail server the app is connecting to.
In general it's not possible with IMAP. IMAP is intended for reading email, not for sending. You may try to fake email sender when sending email via SMTP protocol.
This is exactly what spam senders do (and what mail servers tries to detected).
It used to easy. SMTP dialog follows:
S: MAIL FROM:<your.friend#example.com>
R: 250 OK
S: RCPT TO:<somene#example.com>
R: 250 OK
S: DATA
R: 354 Start mail input; end with <CRLF>.<CRLF>
S: Blah blah blah...
S: ...etc. etc. etc.
S: <CRLF>.<CRLF>
R: 250 OK
But now things are getting more interesting. There is still race of arms between those two - for example:
Attack
Try to submit false "FROM:" address during communication with SMTP server.
Defense: SMTP server may require you to authenticate and allow only 'from' address associated with your account.
Another attack
Try to use third party SMTP server that has no such rule.
Defense (third party SMTP server): Allow sending only emails with 'from' domains matches with 'own' domains.
Defense (recipient's SMTP server): Add SPF record to your domain. This records includes all hosts that are allowed to send email with sender in this domain. If the email is sent from not allowed host increase it's spam score or delete it.
Another attack
Infect computer which is allowed to send email for specified domain with virus and send emails using it.
Defense: Educate users and/or use good antivirus.
And so on... There will be always ways how to fake sender's email address and how to fake it. Check following links for more info:
RFC 821 - SMTP
So You'd Like to Send Some Email (Through Code)
The C# application sends an email using System.Net.Mail.SmtpClient.Send
The application's log file shows that the Send method succeeded at 11:39
When I open the email in Outlook and do File|Properties, it shows
Sent: 11:39 AM
Received: 11:41 AM
If I go to View|Options , the headers show:
Received: from XXX by YYY with Microsoft SMTPSVC [...]
11:41:15
[...]
Date: 9 Dec 2009 11:38:51
[...]
X-OriginalArrivalTime: [...] 11:41:15.0250
So my question is - if the Send method came back at 11:39, but the server only received it at 11:41, where did the email spend the 2 minutes?
In other words, is there something that needs to be configured on the machine that runs the application or on the Exchange server?
The first thing to check is that the client and Exchange server have their times in sync. Usually there's more noticeable problems when a server like Exchange is out of sync time-wise, but it's possible to be a couple minutes off and not be noticed for a while.