Solved

Send Email to External Address ASP.Net IIS6

Posted on 2009-05-11
3
862 Views
Last Modified: 2013-11-30
I have developed an ASP.Net Web Site (VB) and need to be able to send emails to external addresses. We are using an Exchange Server for email but it will not send to external addresses, only internal. What a pain. I installed the Virtual SMTP Server in IIS6 and specified our ISP in the Smart Host box in Delivery options. I also added 127.0.0.1 to Relay Restrictions to allow... No where can I find how the <Mailsettings> section of my web.config should be set to work with the virtual smtp server in IIS6. In my code, see below, what should I specify in place of our exchange server address? How do I get this to work??
Dim smtp As New SmtpClient("exchangeserveraddress")
 

What do I specify instead of "exchangeserveraddress" if I need to use the Virtual SMTP Server??

Open in new window

0
Comment
Question by:michouis
3 Comments
 
LVL 9

Accepted Solution

by:
tillgeffken earned 500 total points
ID: 24355155
The web.config settings below will ensure that SmtpClient objects get initialized with the settings from web.config if not overridden.

web.config:
 

<configuration>

  <!-- Add the email settings to the <system.net> element -->

  <system.net>

    <mailSettings>

      <smtp>

        <network 

             host="relayServerHostname" 

             port="portNumber"

             userName="username"

             password="password" />

      </smtp>

    </mailSettings>

  </system.net>

Open in new window

0
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
ID: 24357317
I am assuming that you are using ASP.NET 2.0 or above and you have missed to provide authentication before sending the mail using the SMTP/Exchange Server.

First to quickly answer your "exchangeserveraddress" question, you can provide the machine name if the server is accessible on LAN or fully qualified URL. However, it is always a recommended or good practice to provide IP Address of the server and also provide the port number using the overload constructor.

Check the code snippet which has been copied and modified from: http://www.systemnetmail.com/faq/4.2.aspx. Make sure the Network Credentials (User Name/Password) provided have appropriate account in Mail Server.

Further, some public web-based mail services such as Gmail allow to send emails using Gmail Accounts. For this purpose, you have to provide a little extra information to the SmtpClient object. Sample code for sending email from Gmail is also in snippet.
'create the mail message

Dim mail As New MailMessage("from@mycompany.com", "you@yourcompany.com")
 

'set the content

mail.Subject = "This is an email"

mail.Body = "this is the body content of the email."
 

'set extra properties of the MailMessage object as per requirements
 

'send the message

Dim smtp As New SmtpClient("127.0.0.1")
 

'to authenticate we set the username and password properites on the SmtpClient

smtp.Credentials = New NetworkCredential("username", "secret")

smtp.Send(mail)
 

'''SEND EMAIL USING GMAIL ACCOUNT

'create the mail message

Dim mail As New MailMessage("from@mycompany.com", "you@yourcompany.com")
 

'set the content

mail.Subject = "This is an email"

mail.Body = "this is the body content of the email."
 

'set extra properties of the MailMessage object as per requirements
 

'send the message

Dim smtp As New SmtpClient("smtp.gmail.com", 587)
 

smtp.DeliveryMethod = SmtpDeliveryMethod.Network

smtp.EnableSsl = True

smtp.UseDefaultCredentials = False
 

'to authenticate we set the username and password properites on the SmtpClient

smtp.Credentials = New NetworkCredential("myaccount@gmail.com", "thepassword")

smtp.Send(mail)

Open in new window

0
 

Author Closing Comment

by:michouis
ID: 31580157
The actual solution was to run System Manager on our Exchange server and get to the SMTP Protocol ACCESS option and add the Web Server IP address as an allowed IP address for relaying messages... I do not want to place the hst and credentials in the web.config file... I set the host in the smart host box in my web server virtual smtp folder etc...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Junk folder 23 142
'Include' Syntex in domain records 6 47
ASP.NET reading ATOM 2 51
I need help displaying 2 models in one view in my MVC.Net application with C# code behind 5 30
Hello Friends, My friends and relatives always ask me how to delete all the various types of emails at once in our g-mail  or windows live account.  So I researched this topic to find a unique solution to this query.  Here it is for those who do …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now