troubleshooting Question

running Send Email function from IIS test server

Avatar of ITDeptAtPCS
ITDeptAtPCS asked on
Microsoft IIS Web ServerEmail Protocols
19 Comments1 Solution486 ViewsLast Modified:
Hello, my question today has to do with running an smtp relay from a test server. I have two test servers PCStest and PCSDev1 which are IIS and I am running c# and asp.net code on them. Full read and write permissions are given to users on both of the servers. Yet when I try to run a smtp function from either server , the email is sent but with only a subject, and no text written in the body. The body is supposed to be populated by data from a form using the code below labeled contstructenrollemail. The string returned from that method is then passed in as the body of the email message. The email message fyi is constructed as a system.net.mailmessage object. It is created and sent in the code below labeled createemail. I have enabled every permission I could think of on the servers and have had no luck. I also attempted to write the created body string to a file on either server and that too failed. If I run any of the below code locally there are no problems at all. Which I was thinking it was an IIS issue. Has anyone here ever experienced a problem like this or have any suggestions as to what the issue could be?
//CREATE EMAIL Function
public static bool createEmail(System.String sTo, System.String sMessage, System.String sSubject)
{
			
        bool itworked = false;
 
            try
            {
 
                System.String sHostname = new System.Text.StringBuilder().ToString();
                System.String sFrom = new System.Text.StringBuilder().ToString();
 
                sHostname = Config.get_Renamed("email.hostname");
                sFrom = Config.get_Renamed("email.from");
 
                System.IO.File.WriteAllText("C:\\Documents andSettings\\gormleyf\\Desktop\\AppDev\\message.txt", sMessage);
 
                // Define message
 
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                System.Net.Mail.MailAddress adrs = new System.Net.Mail.MailAddress(sFrom);
                message.From = adrs;
 
                System.Net.Mail.MailAddress adrss = new System.Net.Mail.MailAddress(sTo);
 
                message.To.Add(adrss);
                
                message.Subject = sSubject;
 
                message.Body = (System.String)sMessage;
 
                // Send the message
                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                client.Host = sHostname;
                client.Send(message);
                itworked = true;
                return true;
            }
 
//CONSTRUCTENROLLEMAIL function
 public static System.String constructEnrollFormEmail(BookOrderForm bookOrderForm)
            {
                System.String body = null;
                
                try
                {
                    System.Text.StringBuilder emailMessage = new System.Text.StringBuilder();
                    if (bookOrderForm.New_client == 1)
                        emailMessage.Append("New Client: true");
                    else
                        emailMessage.Append("New Client: false");
 
                    emailMessage.AppendFormat("Plan Name:  {0}  ",bookOrderForm.Plan_name);
                    emailMessage.AppendFormat("Target Date:  {0}  ", bookOrderForm.Target_date);
                    emailMessage.AppendFormat("# of Booklets Needed:  {0} ", bookOrderForm.No_of_booklets);
                    emailMessage.AppendFormat("Name:  {0}  ", bookOrderForm.Name);
                    emailMessage.AppendFormat("Company Name:  {0} ", bookOrderForm.Company_name);
                    emailMessage.AppendFormat("Address:  {0}  ", bookOrderForm.Address);
                    emailMessage.AppendFormat("State:  {0}  ", bookOrderForm.State);
                    emailMessage.AppendFormat("Zip:  {0}  ", bookOrderForm.ZipCode);
                    emailMessage.AppendFormat("Phone:  {0}  ", bookOrderForm.Phone);
                    emailMessage.AppendFormat("Email Address:  {0}  ", bookOrderForm.Email);
 
                    if (bookOrderForm.Authorize_cost_of_overnight_mail == 1)
                        emailMessage.Append("Authorize overnight mail costs: true");
                    else
                        emailMessage.Append("Authorize overnight mail costs: false");
 
                    if (bookOrderForm.Will_advisor_pay_for_booklets == 1)
                        emailMessage.Append("Who will pay for the booklets: Plan Sponsor");
                    else
                        emailMessage.Append("Who will pay for the booklets: Advisor");
 
                    if (bookOrderForm.Are_any_plan_changes == 1)
                        emailMessage.Append("Any Investment Change: Yes");
                    else
                        emailMessage.Append("Any Investment Change: No");
 
                    if (bookOrderForm.Order_wallet_cards == 1)
                    {
                        emailMessage.Append("Order Accountlink Wallet Cards: Yes");
                        emailMessage.AppendFormat("Accountlink Wallet Card Amount:  {0}  ", bookOrderForm.Wallet_card_amount);
                    }
                    else
                        emailMessage.Append("Order Accountlink Wallet Cards: No");
 
                    emailMessage.AppendFormat("Advisor's Name:  {0} " , bookOrderForm.Name);
                    emailMessage.AppendFormat("Firm Name:  {0} ", bookOrderForm.Company_name);
                    emailMessage.AppendFormat("Phone Number:  {0}"  , bookOrderForm.Phone);
                    emailMessage.AppendFormat("Email Address:  {0} " ,bookOrderForm.Email);
 
 
                    body = emailMessage.ToString();
                    return body;
ASKER CERTIFIED SOLUTION
cj_1969

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 19 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros