hmmmm. im not sure... the "to", "from" fields all end up in the header...
but ill post the code I use... hope it helps.
Adam -
http://www.aejw.com/?page=contact
public class emailMsg{
#region propertys
private string ls_smtpServer="localhost"; public string
smtpServer{get{return(ls_smtpServer);}set{ls_smtpS erver=value;}}
private string ls_Username=""; public string
smtpUserName{get{return(ls_Username);}set{ls_Usern ame=value;}}
private string ls_Password=""; public string
smtpUserPassword{get{return(ls_Password);}set{ls_P assword=value;}}
private bool lf_useThreading=false; public bool
useThreading{get{return(lf_useThreading);}set{lf_u seThreading=value;}}
private string ls_toAddress=""; public string
to{get{return(ls_toAddress);}set{ls_toAddress=valu e;}}
private string ls_fromAddress=""; public string
from{get{return(ls_fromAddress);}set{ls_fromAddres s=value;}}
private string ls_subjectText=""; public string
subject{get{return(ls_subjectText);}set{ls_subject Text=value;}}
private string ls_bodyText="test"; public string
body{get{return(ls_bodyText);}set{ls_bodyText=valu e;}}
public enum emailContentType{
text=0,
html=1,
}
private emailContentType lt_Content=emailContentType.text;
public emailContentType
bodyContent{get{return(lt_Content);}set{lt_Content =value;}}
#endregion
#region send mail functions
public void sendMail(){emailMsg.sendMail(this);}
static public void sendMail(emailMsg pMessage) {
//prep message
if(pMessage==null){
throw new Exception("'emailMessage' object is required");
}
if(pMessage.useThreading){
//set thread info
if(lo_EmailThreads==null) lo_EmailThreads=new
System.Collections.ArrayList();
int iSel=lo_EmailThreads.Add(pMessage);
//start thread
System.Threading.Thread oThread = new System.Threading.Thread(new
System.Threading.ThreadStart(z_ThreadSend));
oThread.Name=iSel.ToString();
oThread.Start();
}else{
//start non thread
z_SendMail(pMessage);
}
}
#endregion
#region private functions
private static System.Collections.ArrayList lo_EmailThreads = null;
private static void z_ThreadSend(){
int i=Convert.ToInt32(System.Threading.Thread.CurrentT hread.Name);
emailMsg oMessage = (emailMsg)lo_EmailThreads[i];
lo_EmailThreads.Remove(i);
z_SendMail(oMessage);
}
private static void z_SendMail(emailMsg pMessage){
System.Net.Mail.SmtpClient client = new
System.Net.Mail.SmtpClient();
client.Host = pMessage.smtpServer;
client.Send(pMessage.z_getMessage());
System.Threading.Thread.Sleep(10);
}
internal System.Net.Mail.MailMessage z_getMessage(){
System.Net.Mail.MailAddress to = new
System.Net.Mail.MailAddress(this.to);
System.Net.Mail.MailAddress from = new
System.Net.Mail.MailAddress(this.from);
System.Net.Mail.MailMessage oMailMessage = new
System.Net.Mail.MailMessage(from, to);
oMailMessage.Subject = this.subject;
oMailMessage.Body = this.body;
oMailMessage.IsBodyHtml = (lt_Content == emailContentType.html);
oMailMessage.Priority = System.Net.Mail.MailPriority.Normal;
return(oMailMessage);
}
#endregion
}
<cl********@gmail.comwrote in message
news:11**********************@48g2000cwx.googlegro ups.com...
I've had nothing but trouble from the System.Net.Mail objects, but I
finally need to make them work, and I can't for the life of me see what
I'm doing wrong.
I pared back my mail transaction to the bare minimum:
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("<my
mail server IP>", 25);
smtp.Send("<one of my email addresses>", "<another of my email
addresses>", "Hello", "World");
And on the smtp.Send() command I get back a SmtpException {"Failure
sending mail."}, {An invalid character was found in the mail header.}.
An inspection of the MailMessage object (before I simplified that away)
showed that there were no items in the header before this exception. A
packet trace during the exception shows that the SMTP server responds
properly and the object immediately replys with a "QUIT".
I would greatly appreciate any insight that could be offered.
Thanks,
Andy