locked
Sending SMTP Mail using Windows 2008 R2 SMTP Virtual Server

    Question

  • Hello,

    I want to send mails using a WPF Application or Windows Service that is hosted on a OnPrem Windows 2008 R2 Server using the SMTP Virtual Server.

    On SMTP Server here is what I did (SMTP Virtual Server #1 properties):
    - General -> IP Address: All Unassigned
    - Access -> Authentication: Anonymous and Integrated Windows Authentication are checked.
    - Delivery -> "Outbound Security: -> Specified the UserID and Pwd for Integrated Windows Authentication (Domain service user)
    - Advanced -> "Advanced" -> Masquerade domain: blank.  FQDN:  machinename.domainname (Ex: mach1.corp.contoso.com).  Smart host:  localhost.
    - Security -> Aded the above domain service user in the list.

    My Application has as below:

    MailMessage msg = new MailMessage();
    msg..... set all property here....
    
    SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["SMTPServer"].ToString(), 25);
    smtp.Send(msg);
    MessageBox.Show("Mail Sent!", "SMTP Test Client", MessageBoxButton.OK, MessageBoxImage.Information);
    msg.Dispose();
    
    I get mail sent, but the non of the address in the email receive any email. Where might be the issue here?
    Thanks.
     
    • Moved by Alexander Sun Tuesday, May 29, 2012 8:04 AM Move to more appropriate forum (From:Visual C# Language)
    Monday, May 28, 2012 11:27 AM

All replies

  • Hello,

    I want to send mails using a WPF Application or Windows Service that is hosted on a OnPrem Windows 2008 R2 Server using the SMTP Virtual Server.

    On SMTP Server here is what I did (SMTP Virtual Server #1 properties):
    - General -> IP Address: All Unassigned
    - Access -> Authentication: Anonymous and Integrated Windows Authentication are checked.
    - Delivery -> "Outbound Security: -> Specified the UserID and Pwd for Integrated Windows Authentication (Domain service user)
    - Advanced -> "Advanced" -> Masquerade domain: blank.  FQDN:  machinename.domainname (Ex: mach1.corp.contoso.com).  Smart host:  localhost.
    - Security -> Aded the above domain service user in the list.

    My Application has as below:

    MailMessage msg = new MailMessage();
    msg..... set all property here....
    
    SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["SMTPServer"].ToString(), 25);
    smtp.Send(msg);
    MessageBox.Show("Mail Sent!", "SMTP Test Client", MessageBoxButton.OK, MessageBoxImage.Information);
    msg.Dispose();
    I get mail sent, but the non of the address in the email receive any email. Where might be the issue here?
    Thanks.
     
    • Merged by Alexander Sun Tuesday, May 29, 2012 8:07 AM Duplicate
    Monday, May 28, 2012 12:34 PM
  • Relay restrictions sound like your issue. The SMTP server is accepting the mail, but it cant pass it on. Check the SMTP logs.


    "Programming is an art form that fights back"

    Monday, May 28, 2012 8:04 PM
  • Relay Restrictions:
    All except the list below is selected and the list is empty.
    Also Allow al computers which successfully authenticate to relay, regardless of the list above is checked.

    What should be the actual settings for this page?
    And where should I check SMTP log? Shall I enable the SMTP log and look that or some where in System Log?

    Thanks.

    Edit: Log here:
    #Software: Microsoft Internet Information Services 7.5
    #Version: 1.0
    #Date: 2012-05-29 01:50:30
    #Fields: time c-ip cs-method cs-uri-stem sc-status
    01:50:30 10.12.21.66 EHLO - 250
    01:50:30 10.12.21.66 MAIL - 250
    01:50:30 10.12.21.66 RCPT - 250
    01:50:30 10.12.21.66 RCPT - 250
    01:50:30 10.12.21.66 RCPT - 250
    01:50:30 10.12.21.66 DATA - 250
    01:50:38 10.12.21.66 QUIT - 240
    01:51:28 10.12.21.66 EHLO - 250
    01:51:28 10.12.21.66 MAIL - 250
    01:51:28 10.12.21.66 RCPT - 250
    01:51:28 10.12.21.66 RCPT - 250
    01:51:28 10.12.21.66 RCPT - 250
    01:51:28 10.12.21.66 DATA - 250
    01:51:32 10.12.21.66 QUIT - 240
    #Software: Microsoft Internet Information Services 7.5
    #Version: 1.0
    #Date: 2012-05-29 01:56:47
    #Fields: time c-ip cs-method cs-uri-stem sc-status
    01:56:47 172.19.0.206 EHLO - 250
    01:56:47 172.19.0.206 MAIL - 250
    01:56:47 172.19.0.206 RCPT - 250
    01:56:47 172.19.0.206 RCPT - 250
    01:56:48 172.19.0.206 RCPT - 250
    01:56:48 172.19.0.206 DATA - 250
    01:56:57 172.19.0.206 QUIT - 240

    01:58:24 10.12.21.66 EHLO - 250
    01:58:24 10.12.21.66 MAIL - 250
    01:58:24 10.12.21.66 RCPT - 250
    01:58:24 10.12.21.66 RCPT - 250
    01:58:24 10.12.21.66 RCPT - 250
    01:58:24 10.12.21.66 DATA - 250
    01:58:28 10.12.21.66 QUIT - 240

    Edit:
    I see mails are dropped in Badmail folder and the it looks like:


    Delivery to the following recipients failed.

           testemail@contoso.com

     

    --9B095B5ADSN=_01CD3D3DA943B66100000004redmond.corp.mic
    Content-Type: message/delivery-status

    Reporting-MTA: dns;contoso.corp.com
    Received-From-MTA: dns;ServicesDev
    Arrival-Date: Mon, 28 May 2012 18:58:24 -0700

    Final-Recipient: rfc822;testemail@contoso.com
    Action: failed
    Status: 5.3.5

    Note:  testemail@contoso.com is a valid email and I changed the email here in post.

    • Edited by Prabhat_IE Tuesday, May 29, 2012 2:12 AM
    Tuesday, May 29, 2012 1:49 AM
  • You are using System.web.Mail or System.Net.Mail?

    System.Web.Mail has obsolete if I am right.

    Use the System.Net.Mail.

    http://www.codeproject.com/Tips/165548/C-Code-snippet-to-send-an-Email-with-attachment-fr

    chanmm


    chanmm

    Tuesday, May 29, 2012 3:38 AM
  • I am using:
    using System.Net.Mail;
    using System.Net;
    Also here is more observations:

    Relay Restrictions Settings:
    "All except the list below" is selected and the list is empty.
    Also "Allow all computers which successfully authenticate to relay, regardless of the list above" is checked.

    What should be the actual settings for this page?
    Here is how the Log looks like:

    #Software: Microsoft Internet Information Services 7.5
    #Version: 1.0
    #Date: 2012-05-29 01:50:30
    #Fields: time c-ip cs-method cs-uri-stem sc-status
    01:50:30 10.12.21.66 EHLO - 250
    01:50:30 10.12.21.66 MAIL - 250
    01:50:30 10.12.21.66 RCPT - 250
    01:50:30 10.12.21.66 RCPT - 250
    01:50:30 10.12.21.66 RCPT - 250
    01:50:30 10.12.21.66 DATA - 250
    01:50:38 10.12.21.66 QUIT - 240
    01:51:28 10.12.21.66 EHLO - 250
    01:51:28 10.12.21.66 MAIL - 250
    01:51:28 10.12.21.66 RCPT - 250
    01:51:28 10.12.21.66 RCPT - 250
    01:51:28 10.12.21.66 RCPT - 250
    01:51:28 10.12.21.66 DATA - 250
    01:51:32 10.12.21.66 QUIT - 240
    #Software: Microsoft Internet Information Services 7.5
    #Version: 1.0
    #Date: 2012-05-29 01:56:47
    #Fields: time c-ip cs-method cs-uri-stem sc-status
    01:56:47 172.19.0.206 EHLO - 250
    01:56:47 172.19.0.206 MAIL - 250
    01:56:47 172.19.0.206 RCPT - 250
    01:56:47 172.19.0.206 RCPT - 250
    01:56:48 172.19.0.206 RCPT - 250
    01:56:48 172.19.0.206 DATA - 250
    01:56:57 172.19.0.206 QUIT - 240

    01:58:24 10.12.21.66 EHLO - 250
    01:58:24 10.12.21.66 MAIL - 250
    01:58:24 10.12.21.66 RCPT - 250
    01:58:24 10.12.21.66 RCPT - 250
    01:58:24 10.12.21.66 RCPT - 250
    01:58:24 10.12.21.66 DATA - 250
    01:58:28 10.12.21.66 QUIT - 240

    And I see mails are dropped in Badmail folder and the it looks like:

    Delivery to the following recipients failed.

           testemail@contoso.com

    --9B095B5ADSN=_01CD3D3DA943B66100000004redmond.corp.mic
    Content-Type: message/delivery-status

    Reporting-MTA: dns;contoso.corp.com
    Received-From-MTA: dns;ServicesDev
    Arrival-Date: Mon, 28 May 2012 18:58:24 -0700

    Final-Recipient: rfc822;testemail@contoso.com
    Action: failed
    Status: 5.3.5

    Note:  testemail@contoso.com is a valid email and I changed the email here in post.

    • Edited by Prabhat_IE Tuesday, May 29, 2012 4:20 AM
    Tuesday, May 29, 2012 4:16 AM
  • Check to see if the mail is getting stuck in the SMTP queue. For IIS SMTP you used to be able to do this by looking in the queue directory. Newer IIS versions probably have a GUI option to look.

    "Programming is an art form that fights back"

    Tuesday, May 29, 2012 2:24 PM
  • Are any of the emails getting through?  What version of Visual Studio are you using?

    First the From address of the email and the account of the email has to match.  SMTP has two basic modes of operating.  First is to use the settings on your PC (see Control Panel - Mail settings), and the Second method is to send the mail by the Network to a Mail Server and use Credientials properties to logon to the mail server.  Visual Studio 2008 defaulted to the 2nd methods while 2010 defaults to the 1st method.

    Where is the bad mail folder located?  Is it inside a mail account or just in a folder on the PC?


    jdweng

    Tuesday, May 29, 2012 4:47 PM
  • The mails are stuck in Badmail folder.
    I think there is no GUI to look at the queue folder.
    Tuesday, May 29, 2012 5:34 PM
  • Non of the mails are success.
    Also I use VS 2010, and testing from VS does not work. Also I copy the .EXE of the application to target (SMTP) server and execute from there as well.

    To me it looks like the from address should be a VALID email. I will double check this. Looks like I am approaching towards solution :).
    Tuesday, May 29, 2012 5:36 PM
  • What is the path of the badmail folder?  ro is it inside Outllook?


    jdweng

    Tuesday, May 29, 2012 5:39 PM
  • See if there are any events in the app event log for SMTP that say why they are bad.

    "Programming is an art form that fights back"

    Tuesday, May 29, 2012 8:59 PM
  • See the following in this KB article.:

    • Numeric Code: 5.3.5

      Possible Cause: A loop-back situation where the server is configured to loop back on itself was detected.


      Troubleshooting: If you have multiple SMTP virtual servers that are configured on your Exchange computer, make sure that they are serving unique incoming ports and that the outgoing SMTP port configuration is valid to avoid looping between local virtual servers. Check the configuration of the server's connectors for loops. For example, make sure that no connectors exist that have the address space of the local organization, unless you share the domain and you do not select Use DNS to route to each address space on this connector. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
      321721  (http://support.microsoft.com/kb/321721/ ) Sharing SMTP address spaces in Exchange 2000 Server and Exchange Server 2003
      Make sure that if there are multiple virtual servers, that none are set to All Unassigned.
    Wednesday, May 30, 2012 1:58 AM
  • cheongoo: I'm not sure looking at the service in this case is applicable.  The first question we should ask is if an outlook account is working on the computer.  We should not be using SMTP using a PC mail account if Outlook doesn't work on the computer, we instead should use network credentials and use a POP3 account.

    We should also check the Control Panel - Mail Settings for multiple accounts.  The control Panel Mail Account may contain obsolete account information that doesn't work and we will never be able to get SMTP in the software to work without manually configuring the computer properly.


    jdweng

    Wednesday, May 30, 2012 3:27 AM
  • The error code suggest that it's a email routing problem. You can't jump over to say there're authentication issue unless you got this one cleared.

    Say, you try to help someone over the phone when you hear he can't go home (perheps he just have a new home). It's pretty pointless to worry about whether the person got the right key, when he's still wondering in the street and not sure how to get to his home because the traffic light and sign is a mess there. Someone in the street is helpful to tell this guy he noticed this guy passing the same place again and again that if he has some place to go, something is wrong. Try to make sure the guy can find his way home first and worry about other things then.



    • Edited by cheong00 Wednesday, May 30, 2012 4:14 AM
    Wednesday, May 30, 2012 4:08 AM
  • Since in this case the user isn't using Network routing, the server is obtained from the Control Panel Email Account.  the user doesn't have direct access to the service that you are refering to which sits below the email account.  So if the email account isn't configured properly you will get a routing error.

    SMTPClient

    Email Account

    Service


    jdweng

    Wednesday, May 30, 2012 4:17 AM
  • When I say it's email routing problem, it's natural to be out of his reach. Get an experienced system admin to help making sure the email knows where to go, instead of sitting here and trying to figure out something you're not in position to tinker. In this case the asker may need to control the DNS records on the server. I could have suggest try to add DNS server role and add a correct MX record to point SMTP to the correct address. (It's not uncommon to intentionally misconfigure the MX record inside intranet to get rid of virus sending email through intranet as "yourself", if all people use Outlook with Exchange connection it should be matter anyway. You had better ask the network team just in case it's true.)

    P.S.: I can't see the asker post anything about "the server is obtained from the Control Panel Email Account". Where is it?

    P.P.S: From the configuration I see on the first post, he seems to incorrectly set the smarthost to localhost, so it loops back to itself. Ask the system admin what should it be.

    Wednesday, May 30, 2012 6:39 AM
  • cheong00 : It is very simple to determine if there is a routing problem by using Outlook.  If the outlook account is working properly it eleminates a lot of problems including any service problem you are suspecting.  At some companies SMTP does not get configured on a PC until Outlook is used for the first time.  So running Outlook is necessary to fix the problem.

    My company has a number of facilities.  When I go to another facility the computers recognize my account and configures the computer automatically. but doesn't setup my email account properly.  I have to go into control panel - mail and perform a search for my email account and email  server which is located at my home location.  the installation software on the PC only searches the local email server for accounts.  It is very simple problem to fix.

    I don't expect the user to know how to make this fix.  but the syptoms of the problem can easily be recognized by Outlook not working.  The fix is not going and changing the service, the fix is properly configuring the Control Panel Settings.


    jdweng

    Wednesday, May 30, 2012 9:10 AM
  • Just note that testing in Outlook doesn't help if the company is configured to use Exchange connection as I said in the previous post.

    And saying "some companies SMTP does not get configured on a PC until Outlook is used for the first time" is plain wrong information. SMTP server lives on Exchange server or some other server and NOT on the client PC. And Outlook is rarely installed on these servers. (With noted exception of Exchange 2000 or before where Exchange Administrators have permission to read emails in every single mailbox on the server, so they'll typically install on there)

    As far as SMTP server's concern, it only takes the parameter it saves. (SMTP was part of IIS, not Outlook or even Exchange. This changed with Win2008R2, but only changed to not depending on anything at all). How could you expect Outlook understand where the parameters of all these version of SMTP remains as mystery to me.

    I don't expect a user know how to fix this, so it's only the right thing to do to ask them consult network admins. As I've said before, there's legitimate reason to intentionally set network setting to provide false parameters. In such case there no chance for any kind of autodetection to work. On the other hand, network admins should know these parameters, and they should know how to configure the SMTP server (as part of MCP courses towards "Servers" kind of certification).

    Just let the experts do their job. Anyone who set "smarthost" to "localhost" (unless the server has multiple SMTP server instance running) clearly need guidence from someone who really understand the SMTP settings to configure it properly.

    EDIT: Bold the reason why the email cannot be sent in case someone may overllok the reason.








    • Edited by cheong00 Friday, September 07, 2012 8:15 AM
    Wednesday, May 30, 2012 9:41 AM