Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting mailServerName in C# .Net for email feedback form

Posted on 2007-11-16
1
Medium Priority
?
1,136 Views
Last Modified: 2013-12-18
Hi

I'm writing an application that has a html feedback form included. I am trying to send the information back through email but am having difficulty when setting the MailServerName.
 
This is the code I am using

private void SendMail(string from, string body)
    {
        string mailServerName = "smtp.MyServerName.com";
        MailMessage message = new MailMessage(from, "test@test.com", "feedback", body);
        SmtpClient mailClient = new SmtpClient();
        mailClient.Host = mailServerName;
        mailClient.Send(message);
        message.Dispose();
    }

The error that I am getting when I run the script is "SmtpException was unhandled by User code - Failure Sending Mail" and it points to the line mailClient.Send(message);

So I figure it is having trouble when I am putting in the ServerName, I'm new to this, is there anyway I can change this around to take the IP address instead to see if that works?
0
Comment
Question by:IRLWEB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 16

Accepted Solution

by:
McExp earned 500 total points
ID: 20300476
See below for some sample code, it sends an email via an account which requires authentication: -

            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

            //set the addresses
            mail.From = new System.Net.Mail.MailAddress("errorMgr@MySite.com");
            mail.To.Add("TestUser@SomeSite.com");
            mail.Subject = "The Subject";
            mail.Body = "This is the messsage Body;

            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("mail.MySite.com");
            //Alternativly you can use an IP address
            //System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("192.168.11.1");
            smtp.Credentials = new System.Net.NetworkCredential("errorMgr@MySite.com", "errorMgr");
            smtp.Send(mail);
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Resolve DNS query failed errors for Exchange
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

705 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