Solved

Setting mailServerName in C# .Net for email feedback form

Posted on 2007-11-16
1
1,133 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 125 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…

623 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