MailSettings for Remote Mail Server using SMTP Network Windows 2008 Web Server
Fixing the dreaded: Mail error: Syntax error in parameters or arguments. The server response was: 5.7.1 xx@xx.xx... Permission Denied
I use a separate machine for my mail server to send online mails via smtp. This setup fix might be old hat for some of you, but for me it's new...
Using the older 2.x frameworks, when sending mail, I didn't have anything in my web.config. I did all my setup in a SendMail class I created.
I would pass in a client, username and password (notice this was my MAILSERVER user name and password):
Dim m_smtpclient As String = "xx.xx.xx.xx"
Dim m_smtpUsername As String = "MyMailServerUserName"
Dim m_smtpPassword As String = "MyMailServerUsersPassword"
then later I'd have this:
Dim smtp As New SmtpClient(m_smtpclient)
If Not String.IsNullOrEmpty(m_smtpUsername) And Not String.IsNullOrEmpty(m_smtpPassword) Then
' to authenticate we set the username and password properites on the SmtpClient
smtp.Credentials = New System.Net.NetworkCredential(m_smtpUsername, m_smtpPassword)
End If
smtp.Send(mail)
Now, I recently setup Windows 2008 Web Server and IIS7. And none of the above would work at all. I skipped the above and decided to use new examples I found. I snagged a sendmail function from HOW TO: Send email using System.Net.Mail and used the following in my web.config:
<system.net>
<mailSettings>
<smtp from="xx@xx.xx">
<network host="mail.xx.net" port="xx" userName="xx" password="xx"/>
</smtp>
</mailSettings>
</system.net>
But alas, I was still faced with the dread error:
Mail error: Syntax error in parameters or arguments. The server response was: 5.7.1 xx@xx.xx... Permission Denied
I tried numerous, NUMEROUS variations and attempts. Still failure.
I recently experienced a problem with the membership provider not working in IIS7, and the resolution involved a setting in IIS7 that wasn't in IIS6 (or if it is, I never used it and didn't know it existed). So I got to thinking, what is new in IIS7 that I have not seen before.
So I went to IIS7, selected my website, and I see in the Features View an "SMTP E-mail" icon. I clicked it.
It opens up a screen that allows me to setup my email, and how to deliver.
I tried variations for "specify credentials" as this is how I was used to doing it. But still failure. Almost ready to give up, I thought, well, may as well try the Authentication Setting for "Windows."
I clicked that and boom, it worked.
It altered my web config to look like below, and the host is my LAN IP address.
<system.net>
<mailSettings>
<smtp from="">
<network defaultCredentials="true" host="xx.xx.xx.xx" port="25" />
</smtp>
</mailSettings>
</system.net>
Notice the above is very stripped down. I add the "from" address in my actual SendMailMessage function, which I snagged from HOW TO: Send email using System.Net.Mail, but you could put it in there. I prefer just having the option to pass it into my function based on what I want the "from" to be for that particular mail.
Anyway, there ya go, How to setup the MailSettings for a remote mail server. Note: this mail server is on the same network as my web server. This mail server is setup in my firewall to allow smtp settings as needed. This mail server allows relay from the web server's local IP address.
May your dreams be in ASP.Net!
Nannette