Question

I've got the following vb.net code in a intranet webpage:

Sub SendEmail()
    MMsg = New MailMessage

    MMsg.BodyFormat = MailFormat.Html
    MMsg.From = "intranet@internal_company_name.com"

    MMsg.To = "someone@internal_company_name.com"
    MMsg.Subject = "subject goes here"
    MMsg.Body = "body goes here"
    SmtpMail.SmtpServer = "smpt server goes here"
    SmtpMail.Send(MMsg)
End Sub

This works fine as long as the MMsg.To contains internal company email addresses only, i.e. MMsg.To = "someone@internal_company_name.com;someone_else@internal_company_name.com". As soon as I try to add an external company email into MMsg.To, i.e. MMsg.To = "someone@internal_company_name.com;someone@extermal_company_name.com", when I submit the form on the intranet webpage, I get the following error message:

The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for someone@extermal_company.com

However, the internal email is received successfully and everything is processed on the form. It's just the external email which doesn't get received by the external company and the error which appears on the users screen when they press the submit button.

I've had a search about this, and some solution suggested that I add the localhost ip address and the intranet servers ip address into iis on the intranet. I have done this, and it made no difference. Not sure if I am supposed to restart iis after doing that like I have to restart apache when making changes to apache on a linux server?

Or is it because we have a real smtp server which is separate from the actual intranet server, and I am trying to add the ip addresses to some virtual smtp server in iis in the intranet server?

Or is it something totally different?

Was it helpful?

Solution

The error number is clearly a SMTP Server error number -nothing to do with .NET. A more through description of the error can be found here (PDF link)

Basically it boils down to:

  • If your SMTP server is whitelist based, your external addresses/domains need to be whitelisted. Like Bartdude said above, check with the people that manages the server rules.
  • Maybe you need authentication to use that SMTP server.
  • The destination address/domain is in some kind of blacklist.

Alternatively, why don't you try to use some other SMTP server (like Gmail's, smtp.gmail.com) to check if you can send emails to external addresses?

OTHER TIPS

Most likely the issue is that you need to authenticate before sending email. Put this in your web.config right before the </configuration> tag:

<system.net>
    <mailSettings>
    <smtp from="me@yourdomain.com">
      <network host="mail.yourdomain.com" userName="me@yourdomain.com" password="mypassword" port="25" />
    </smtp>
    </mailSettings>
</system.net>

Of course replace the values in quotes with the values from your mail server. Also you can remove the line where you set the SmtpServer in your code.

HTH, -Brandon

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top