Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Setting mailServerName in C# .Net for email feedback form

Posted on 2007-11-16
1
Medium Priority
?
1,139 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 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The main intent of this article is to make you aware of ‘Exchange fail to mount’ error, its effects, causes, and solution.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
Suggested Courses

886 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