Solved

Setting mailServerName in C# .Net for email feedback form

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Email signatures have numerous marketing benefits. Here are 8 top reasons to turn your email signature into a marketing channel.
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In this video we show how to create an Accepted Domain 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 Mail Flow >> Ac…

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

14 Experts available now in Live!

Get 1:1 Help Now