SmtpClient Won't Authenticate When Inflated From Web.config
Jan 13, 2011
When using the system.net/mail web.config settings to configure my SmtpClient, it fails to deliver emails, with an "protocol error" described best by Base64 encoding and authentication problems:
Example:
With the following Config
<system.net>
<mailSettings>
<smtp from="[URL]">
<network host="[URL]"
port="2525"
defaultCredentials="false"
userName="username"
password="password"/>
</smtp>
</mailSettings>
</system.net>
And the Code:
var tmp = new SmtpClient();
MailMessage msg = new MailMessage();
msg.Subject = "test";
msg.From = new MailAddress("[URL]");
msg.To.Add(new MailAddress("[URL]"));
msg.Body = "test";
tmp.Send(msg);
Produces the error message:
System.Net.Mail.SmtpException: The server committed a protocol violation The server response was: UGFzc3dvcmQ6
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException
& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
However, in the following code where I manually set all the properties, the code runs without exception and the email is delivered.
var tmp2 = new SmtpClient("[URL]", 2525);
tmp2.Credentials = new NetworkCredential("username", "password");
tmp2.UseDefaultCredentials = false;
MailMessage msg = new MailMessage();
msg.Subject = "test";
msg.From = new MailAddress("[URL]");
msg.To.Add(new MailAddress("[URL]"));
msg.Body = "test";
tmp2.Send(msg);
I can specify a port number with SmtpClient object in ASP.NET, what I am wondering is, is that just the port .NET uses to send mail to the SMTP server? Or will that dictate what port for the SMTP server to use? Or is it that it MUST match the port configured for the SMTP server?
Learning how to do a master page in asp.net. Trying to figure out how my style sheet interacts with respects to the master page and content page. I can get HTML tags like body and the style sheet to react. But when I call the ID attribute of a label no styling takes place. What am I missing here as far as interaction? BTW I'm using VS2008
I am having some problems sending emails (using gmail). I have an application that allows a user to send an email, request info, etc. I want the email "from" address to be from the initiating user. I set up the settings in the web.config for the first time. Previously, I had always set up the info directly in the code. The email is sending just fine. However, the from address shows the user name correctly but the email address in the one in the web.config.ie. "User From Name <web.config from address>". In the code, the MailMessage object shows it correctly ("User From Name <User from address>"), and the SMTPClient From address shows the web.config from address. This is going to be confusing for the recipient of the emails to see the config address with the user name.
I tried removing the From address from the config(leaving the required userIDpw for the email logon, but no difference. I also tried removing the config mail settings completely and putting it back in the code. Still no luck.
How can I get the from address to be the valid email address in resulting email?
How do I format the body of the email so it doesn't look so old school :) I've tried sending html through it, but it just comes out as html in the body of the email.
I am working on a project where one of the requirements is to re-write an ASP.NET application. The old ASP.NET application was based on .NET Framework 1.1. The new ASP.NET application is based on .NET Framework 3.5.
One of the functions in the old web application was the ability to send email. The old code used the System.Web.Mail.SmtpMail class, whereas the new web application uses the System.Net.Mail.SmtpClient class.
In testing this on our development servers, everything worked fine. However, we have two beta clients testing out our software, and they both run into problems sending email in the new web application.
The specific exception is as follows:
"Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it"
Both the old and new ASP.NET application are on the same server (Windows Server 2003). They both are using the same Exchange mail server. Why is it that the old ASP.NET application can successfully send email, but the new one cannot?
I looked at the old code, and it did not use any form of authentication, it just specified the sender's email address, the recipient's email address, the subject, body, and server, and sent the message. I did the same thing in the new code, with the only difference being that I used the SmtpClient class.
Below is a code snippet from the new ASP.NET application:
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(messageTo); mail.From = new MailAddress(messageFrom); mail.Subject = messageSubject; mail.Body = messageBody; SmtpClient client = new SmtpClient(); client.Host = smtpServer; client.Send(mail);
i am trying to send email using simple SMTPClient class, as the following code:
[Code]....
when i put the To email to be an Gmail,yahoo, hotmail email "as in example" or another domain.com email, the code is working with no issue, but when i put the recepient email to be any of Google Apps Emails, unfortunately the email didnot received. does the SmtpClient have a problem with google apps?
I use SmtpClient to send email. I want to ensure that the SMTP connection gets closed after each message is sent. I found an explanation of how to do this in the SmtpClient documentation on MSDN:
[URL]
One thing it says is: Call Dispose when you are finished using the SmtpClient. The Dispose method leaves the SmtpClient in an unusable state. After calling Dispose, you must release all references to the SmtpClient so the garbage collector can reclaim the memory that the SmtpClient was occupying.
I have a question about the last part. What exactly does "release all references" mean. How do I do that?
My site sends confirmation emails from a purchase. 95% of the time, it works. The other 5% after clicking the 'Confirm' button that runs the payment and should send the email, i get the following exception:
Details: Exception: Failure sending mail.
Inner Exception: Unable to connect to the remote server
Inner Exception(2): 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 72.167.234.197:25
The code to send the email is this:
Dim smtpClientPayPalSuccess As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient() smtpClientPayPalSuccess.Host = "relay-hosting.secureserver.net" smtpClientPayPalSuccess.Send(mailMessagePayPalSuccess)
FYI: I have confirmed with the hosting that I don't need any credentials, or a different port number than 25. This is also running over https. why this would be happening only a small percentage of the time?
I run a Exchange 2010 server and created an account for one of my websites to send e-mails.
The webserver's IP is even listed on the [Organization Configuration] -> [Hub Transport] -> [Global Settings] -> [Transport Settings] -> [Message Delivery] list.
The code sets a set of Network Credentials, but setting incorrect or correct settings, it doesn't matter; if I list external e-mail addresses, I get a "Mailbox unavailable. The server response was: 5.7.1 Unable to relay for <address>" message, 'local' addresses that are cc-ed, do get delivered...
When checking with telnet, I noticed that the only AUTH option was AUTH NTLM, but when checking the NetworkCredentails, it stated that NTLM should would.
I'm needing to send around 500-2500 emails out at a time to internal email accounts. I'm wondering which was would be faster both for the mail server and for my client app. Should I send multiple emails with just different TO addresses, or just one with multiple BCC addresses? I tried testing this by sending a bunch to my own email and the multiple emails method work, but with the BCC and a single message I only get that single message in my inbox. Shouldn't I be getting as many copies as the number of times I put my address in the BCC line?
If I am on a website#1, and I enter my username/pwd for website#2 on a login page that is on website#1, and website#1, behind the scenes, makes a httpwebrequest to website#2 and posts to the login page. If I then navigate to website#2, should I be logged in? website#2 uses formsauthentication and I call a httpHandler that is on website#2 and pass it the username/password via the querystring. Should this work?
So we have been using the same login gode to connect to various domains in asp.net, with and without MVC. The code works. We have a new server, first one to run server 2008 r2, set up with a directory structure similar to one of the ones that has been working. Using forms authentication, I set up in the web.config
It connects to build the membership provider just fine, but when I tryto use the exact same username and password to login on the forms login page (the stock asp.net stuff) it fails to login. same user, same password that's being used to connect with the membership provider. If I change the password in the web.config, I get an error that it's incorrect, so I know that the membership provider is getting connected with those credentials. What I can't figure out is why can't I use the same credentials to login? I've checked:
The user is not locked.
the user is not set to change password on next logon.
We are developing a browser based intranet application. All users have active directory account, so obvious choice would be use Integrated Windows Authentication. But there will be multiple users accessing same client machine so we decided to use form based authentication (but authenticated against AD). In this scenario what is the best way to authenticate between my ASP.NET application (IIS) and WCF Services (another server IIS 7). I don't want to use asp.Net Compatibility mode or certificate. I am thinking to create another domain account to authenticate ASP.NET and WCF. I am also passing the information about the current ASP.NET user to WCF as header info. Is this the right way to do? The following code will call from ASP.NET to access and get each service method.
// Call WCF service from ASP.NET Application using a new domain account for each call. proxy.ClientCredentials.Windows.ClientCredential.Domain = "mydomain"; ServiceReference.HelloWorldClient proxy = new ServiceReference.HelloWorldClient(); proxy.ClientCredentials.Windows.ClientCredential.UserName = "new_domain_account"; proxy.ClientCredentials.Windows.ClientCredential.Password = "password";
Is there any better way to authenticate WCF from ASP.NET?
I just installed VS2010 and opened the root machine.config and web.config files for review and I found some errors. In machine.config, the following line has errors in both entries for <Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior>. When I hover the cursor over them I get a tooltip text which displays: "The element 'endpointBehaviors' has invalid child element 'Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior'. List of possible elements expected: '...(list of options here)...'. The same problem happens for the second appereance in tag <serviceBehaviors>.
[Code]....
In web.config, there is a tag called <protocols> that has an error with a tooltip text that says "The element 'system.web' has invalid child element 'protocols'. List of possible elements expected: '...(list of options here)...'.
Currently, I work on an ASP.NET project which is hosted under version control and is used on several developer machines, tester machine and production environment.
In three cases, configuration (Web.config) may be different. For example, developer and tester environments use testing SQL Server, whereas in production environment, another SQL Server is accessed, so the connection string is different in those cases.
We want to keep three versions of Web.config in subversion. But modifying each of three files every time we need to add, remove or change a common setting is annoying: it would be nice to have a common, master Web.config, which will be inherited by each of the three Web.config files.
How to set up an ASP.NET project which will use a master configuration file and different slave configuration files on different machines, thus sharing the same project/source code/configuration files in subversion?
When I open my ASP.NET site in IIS and try to open the .NET Trust Levels, I get an error message:
.NET Trust Levels There was an error while performing this operation.
Details: Filename: ?C:inetpubwwwrootmyappweb.config Line number: 445
Error: This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"),or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
I've checked a few places, but I haven't found anything that seems like it would be locking that setting. Is there a systematic way of determining where that setting is locked?
We are experiencing some strange behaviour on one of our ASP.NET web servers (Windows 2003 64-bit). After some activity, two third-party controls are unable to run correctly. One is log4net (it does not write error messages out) and the other is a menu control (it displays eval message instead of picking up its license). The one common thread is that both controls pick up their config from external config files (linked to from web.config).
Just wondering if anyone has any thoughts on this or experienced this in any way. Is it related to file/folder rights? The server has been running fine for a while and just started exhibiting this behaviour. Perhaps it occurs around the time the worker processes are recycled.