|
-
Aug 8th, 2013, 07:25 AM
#1
Problem sending emails with mulitple CCs
I have written a very simple email test page to test the email functionality on my hosted server. This is what I came up with. (addresses changed for posting)
Code:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
public partial class EmailTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
txtTo.Text = "[email protected]";
txtSubject.Text = "testing multiple CCs - Local";
txtCc.Text = "[email protected],[email protected]";
}
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
char[] delimiters = new char[]{',',';'};
string to = txtTo.Text;
string subject = txtSubject.Text;
string body = "Just some text.<br/>Line 2<br /><b>And a bold line</b>";
string[] CCs = txtCc.Text.Split(delimiters);
MailMessage message1 = new MailMessage();
message1.To.Add(to);
message1.CC.Add(txtCc.Text);
message1.Subject = subject;
message1.IsBodyHtml = true;
message1.Body = body;
SmtpClient smtp1 = new SmtpClient();
smtp1.Send(message1);
smtp1.Dispose();
MailMessage message2 = new MailMessage();
message2.To.Add(to);
for (int i = 0; i < CCs.Length; i++)
message2.CC.Add(new MailAddress(CCs[i]));
message2.Subject = subject;
message2.IsBodyHtml = true;
message2.Body = body;
SmtpClient smtp2 = new SmtpClient();
smtp2.Send(message2);
smtp2.Dispose();
litResults.Text = "<div style='color:Red;'>Message Sent</div>";
}
catch (Exception ex)
{
litResults.Text = "<div style='color:Red;'>" + ex.Message + "<br/ >" + ex.StackTrace + "</div>";
}
}
}
As you can see I'm trying 2 different methods to send these emails in the first I'm just using a comma separated list of email addresses and in the second I'm adding each to the collection one at a time. Both methods are documented to be correct. In my local development environment both methods work as expected with single or multiple CC addresses. On the server, the emails are correct if a single CC is used. If you add a second address the resulting email gets screwed up.
This is what the body of the email look like when sent from the server with 2 CC addresses
[email protected]
Date: 8 Aug 2013 00:32:14 -0400
Subject: testing multiple CCs - Local
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Just some text.<br/>Line 2<br /><b>And a bold line</b>
The only difference between the local development environment and the server is the web.config setting defining the mails server. For the local copy the host is set as
smtp.<hostname>.org - where <hostname> contains the acutal domain
on the server the host is set to localhost.
Here are my conclusion
I know the server settings are correct since I'm able to send emails with a single CC.
I know the email code is works since I can run it locally against the hosting server.
Both methods appear to be documented methods for adding mulitpe CCs to an email.
I have opened a ticket with the hosting company and so far they have come back with
I was able to replicate the issue. It seems like the issue with the email script you have added. Please verify the script from your end and try sending mails. If you are still experiencing issue, please get back to us.
So my questions are
Is there anything wrong with my my code in the simple example?
If not, does anyone have any ideas which direction to point my hosts support team?
I have dealt with these guy on a few occassions and have found for the most part they just do a lot of finger pointing and eventually come back saying everything is working as it should be. In this case, I know for sure it isn't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|