Solved

Setting mailServerName in C# .Net for email feedback form

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How do I get the unique ID after insert? 87 89
Expando 4 33
.net Multiple Row Form Fields Data Entry 4 17
Spacing between controls 4 16
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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 a Distribution Group 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 Recipients >>…

707 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

16 Experts available now in Live!

Get 1:1 Help Now