using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net.Mail; using System.IO; using System.Net.Mime; using System.Net; using System.Collections; namespace FloatLine { public partial class FloatLine : Form { public FloatLine() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void bSendSBD_Click(object sender, EventArgs e) { // OK first gather info from the two lines. string sIMEI = cbIMEI.Text; string sMessage = cbMessage.Text; progressBar1.Minimum = 1; progressBar1.Maximum = 6; progressBar1.Step = 1; // Now create the sbd file. string file = "cpf.sbd"; StreamWriter sw = new StreamWriter(file, false); sw.WriteLine(sMessage); sw.Close(); progressBar1.PerformStep(); // Create the message // MailMessage message = new MailMessage("emartin@mbari.org", "Data@SBD.Iridium.com", sIMEI, "SBD Enclosed."); MailMessage message = new MailMessage("magene@mbari.org", "magene@mbari.org", sIMEI, "SBD Enclosed."); //MailMessage message = new MailMessage("emartin@mbari.org", "emartin@mbari.org", sIMEI, "SBD Enclosed."); progressBar1.PerformStep(); // Create the file attachment for this e-mail message. Attachment data = new Attachment(file, MediaTypeNames.Application.Octet); progressBar1.PerformStep(); // Add time stamp information for the file. ContentDisposition disposition = data.ContentDisposition; disposition.CreationDate = System.IO.File.GetCreationTime(file); disposition.ModificationDate = System.IO.File.GetLastWriteTime(file); disposition.ReadDate = System.IO.File.GetLastAccessTime(file); // Add the file attachment to this e-mail message. message.Attachments.Add(data); progressBar1.PerformStep(); //Send the message. SmtpClient client = new SmtpClient("mbarimail.mbari.org"); // Add credentials if the SMTP server requires them. client.Credentials = CredentialCache.DefaultNetworkCredentials; try { client.Send(message); } catch (Exception ex) { Console.WriteLine("Exception caught in CreateMessageWithAttachment(): {0}", ex.ToString()); MessageBox.Show("Error"+ex.ToString(), "FloatLine", MessageBoxButtons.OK, MessageBoxIcon.Error); progressBar1.Value = 1; return ; } progressBar1.PerformStep(); data.Dispose(); progressBar1.PerformStep(); MessageBox.Show("Success: Message Sent", "FloatLine", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }