Here a complete listing of the class module. I'm beginning to think it an encapsulation issue, i.e. needs to be inside <HTML></HTML> since that's the message format.
using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;
using System.Net.Mail ;
using System.Net;
using System.Net.Mime ;
using System.IO;
namespace Gulfstream
{
public partial class Gulfstream : Form
{
string to = "";
string from = "";
string subject = "";
string body = @"";
string server = "";
int port;
string login = "";
string password = "";
public Gulfstream()
{
InitializeCompo nent();
ReadFile();
}
public void ReadFile()
{
//string DefaultValuesPa th = @"DefaultValues .txt";
string DefaultValuesPa th = Environment.Cur rentDirectory + @"\\DefaultValu es.txt";
// Open the stream and read it back.
FileStream fs = File.OpenRead(D efaultValuesPat h);
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(tr ue);
while (fs.Read(b, 0, b.Length) > 0)
{
string strDefaultData = temp.GetString( b);
string CurChar = "";
//string StrToWrite = "";
int Instance = 0;
int OldPos = 1;
int CurPos = 2;
int LastPos = strDefaultData. Length;
while (CurPos < LastPos)
{
CurChar = strDefaultData. Substring(CurPo s, 1);
if (CurChar == "=")
{
Instance++;
switch (Instance)
{
case 1:
// SMTP Server
this.txtServer. Text = strDefaultData. Substring(OldPo s, (CurPos - 2) - OldPos);
OldPos = CurPos;
break;
case 2:
// SMTP Port
this.txtPort.Te xt = strDefaultData. Substring(OldPo s + 1, (CurPos - 3) - OldPos);
OldPos = CurPos;
break;
case 3:
// Login ID
this.txtSerLogi n.Text = strDefaultData. Substring(OldPo s + 1, (CurPos - 3) - OldPos);
OldPos = CurPos;
break;
case 4:
// Login password
this.txtSerPass word.Text = strDefaultData. Substring(OldPo s + 1, (CurPos - 3) - OldPos);
OldPos = CurPos;
break;
case 5:
// From email address
this.txtFrom.Te xt = strDefaultData. Substring(OldPo s + 1, (CurPos - 3) - OldPos);
OldPos = CurPos;
break;
case 6:
// Subject
this.txtSubject .Text = strDefaultData. Substring(OldPo s + 1, (CurPos - 3) - OldPos);
OldPos = CurPos;
break;
case 7:
// Body
this.txtMessage .Text = strDefaultData. Substring(OldPo s + 1, (CurPos - 3) - OldPos);
OldPos = CurPos;
break;
default:
break;
}
}
CurPos++;
}
}
}
fs.Close();
}
public void WriteFile()
{
//String StrToWrite = "=" + this.txtServer. Text + //r//n;
//StrToWrite = StrToWrite + "=" + this.txtSerLogi n.Text + //r//n;
//StrToWrite = StrToWrite + "=" + this.txtSerPass word.Text + //r//n;
//StrToWrite = StrToWrite + "=" + this.txtFrom.Te xt + //r//n;
//StrToWrite = StrToWrite + "=" + this.txtSubject .Text + //r//n;
//StrToWrite = StrToWrite + "=" + this.txtMessage .Text + //r//n + "=";
//string path = @"DefaultValues .txt";
string DefaultValuesPa th = Environment.Cur rentDirectory + @"\\DefaultValu es.txt";
//delete old file first
if (File.Exists(De faultValuesPath ))
{
File.Delete(Def aultValuesPath) ;
}
// Create an instance of StreamWriter to write text to a file.
// The using statement also closes the StreamWriter.
StreamWriter sw = new StreamWriter(De faultValuesPath );
// Add some text to the file.
// sw.Write("This is the ");
sw.WriteLine("= " + this.txtServer. Text);
sw.WriteLine("= " + this.txtPort.Te xt);
sw.WriteLine("= " + this.txtSerLogi n.Text);
sw.WriteLine("= " + this.txtSerPass word.Text);
sw.WriteLine("= " + this.txtFrom.Te xt);
sw.WriteLine("= " + this.txtSubject .Text);
sw.WriteLine("= " + this.txtMessage .Text);
sw.WriteLine("= ");
sw.Close();
}
public void CreateTestMessa ge1(string server, int port)
{
try
{
MailMessage message = new MailMessage(fro m, to, subject, body);
//MailMessage message = new MailMessage(fro m, to);
// information
message.Subject = subject;
message.IsBodyH tml = true;
// message.Body = body + "<div style=\"font-family:Arial\"> <br /><br /><img src=\"@@IMAGE@@ \" alt=\"\"><br /><br /></div>";
message.Body = "<body>" + body + "<div style=\"font-family:Arial\"> <br /><br /><img src=\"@@IMAGE@@ \" alt=\"\"><br /><br /></div>" + "</body>";
string attachmentPath = Environment.Cur rentDirectory + @"\\sig.jpg" ;
System.Net.Mail .Attachment inline = new System.Net.Mail .Attachment(att achmentPath);
string contentID = Path.GetFileNam e(attachmentPat h).Replace(".", "") + "@zofm";
inline.ContentD isposition.Inli ne = true;
inline.ContentD isposition.Disp ositionType = DispositionType Names.Inline;
inline.ContentI d = contentID;
inline.ContentT ype.MediaType = "image/jpg";
inline.ContentT ype.Name = Path.GetFileNam e(attachmentPat h);
message.Attachm ents.Add(inline );
// replace the tag with the correct content ID
message.Body = message.Body.Re place("@@IMAGE@ @", "cid:" + contentID);
SmtpClient client = new SmtpClient(serv er, port);
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client.Credenti als = new System.Net.Netw orkCredential(l ogin, password);
//client.Credenti als = CredentialCache .DefaultNetwork Credentials;
client.Send(mes sage);
lblError.Text = "Email sent!";
}
catch (Exception e)
{
lblError.Text = e.Message.ToStr ing();
}
}
private void butSave_Click(o bject sender, EventArgs e)
{
}
private void butExit_Click(o bject sender, EventArgs e)
{
}
private void butRun_Click(ob ject sender, EventArgs e)
{
lblError.Text = "";
int warn = 0;
if (txtTo.Text == "")
{
warn = 1;
}
else if(txtFrom.Text == "")
{
warn = 1;
}
else if (txtSerPassword .Text == "")
{
warn = 1;
}
else if (txtSubject.Tex t == "")
{
warn = 1;
}
else if (txtPort.Text == "")
{
warn = 1;
}
else if (txtSerLogin.Te xt == "")
{
warn = 1;
}
else if (txtMessage.Tex t == "")
{
warn = 1;
}
int first = 0;
first = txtFrom.Text.In dexOf("@gulfstr eam.com");
if (first == 0)
{
warn = 2;
}
if (warn == 1)
{
lblError.Text = "All fields must be completed!";
}
else if (warn == 2)
{
lblError.Text = "For use by Gulfstream employees only!";
}
else
{
to = txtTo.Text;
from = txtFrom.Text;
login = txtSerLogin.Tex t;
password = txtSerPassword. Text;
subject = txtSubject.Text ;
// loop through body text looking for carriage returns /n
int CurPos = 0;
string CurChar = "";
while (CurPos < txtMessage.Text .Length)
{
CurChar = txtMessage.Text .Substring(CurP os, 1);
if (CurChar == "=")
{
//body += "%0A" + txtMessage.Text .Substring(CurP os, 1);
//body += "<CF><LF>" + " " +txtMessage.Tex t.Substring(Cur Pos, 1);
//body += "'CRLF:\r\n Post CRLF'" + txtMessage.Text .Substring(CurP os, 1);
//body += "<br/>" + txtMessage.Text .Substring(CurP os, 1);
//body += "'\r\n'" + txtMessage.Text .Substring(CurP os, 1);
//body += ":::*" + txtMessage.Text .Substring(CurP os, 1);
//body += "%0d%0a" + txtMessage.Text .Substring(CurP os, 1);
//body += "%0d%0a" + txtMessage.Text .Substring(CurP os, 1);
//body += "%0D%0A" + txtMessage.Text .Substring(CurP os, 1);
body += Environment.New Line + "%0D%0A" + txtMessage.Text .Substring(CurP os, 1);
}
else
{
body += txtMessage.Text .Substring(CurP os, 1);
}
CurPos++;
}
//body = txtMessage.Text ;
server = txtServer.Text;
port = Int32.Parse(txt Port.Text);
CreateTestMessa ge1(server, port);
}
}
private void butExit_Click_1 (object sender, EventArgs e)
{
this.Dispose();
}
private void butSave_Click_1 (object sender, EventArgs e)
{
WriteFile();
lblError.Text = "Default values updated!";
}
private void butLoad_Click(o bject sender, EventArgs e)
{
ReadFile();
}
private void txtTo_TextChang ed(object sender, EventArgs e)
{
}
private void pnlSMTP_Paint(o bject sender, PaintEventArgs e)
{
}
private void lblSerLogin_Cli ck(object sender, EventArgs e)
{
}
}
}
The output...