Hello all im trying to split a string into multiple strings for instance im trying to send an email with a string.
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;
using System.Net.Mail;
using System.Threading;
namespace SendMail
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string SaveEmail = null;
string SavePassword = null;
SmtpClient Mail = new SmtpClient();
MailMessage Message = new MailMessage();
private void Form1_Load(object sender, EventArgs e)
{
Email.Text = Properties.Settings.Default.Email;
Password.Text = Properties.Settings.Default.Password;
}
private void Email_TextChanged(object sender, EventArgs e)
{
string SaveEmail = Email.Text;
Properties.Settings.Default.Email = Email.Text;
Properties.Settings.Default.Save();
}
private void Password_TextChanged(object sender, EventArgs e)
{
string SavePassword = Password.Text;
Properties.Settings.Default.Password = Password.Text;
Properties.Settings.Default.Save();
}
private void Keybox_TextChanged(object sender, EventArgs e)
{
if (Keybox.Text.ToLower().Contains("sendmail"))
{
Thread SendingMail = new Thread(SendMail);
SendingMail.Start();
}
}
public void SendMail()
{
String StringTest = "sendmail [email protected] TestSubject This is what I would type in a message";
char[] Characters = {' '};
string[] StringSplit = StringTest.Replace("sendmail", "").Split(Characters);
foreach(string s in StringSplit)
{
Testbox.Text = s;
}
return;
string SmtpInfo = "";
int SmtpPort = 0;
if (Email.Text.ToLower().Contains("@live.com"))
{
SmtpInfo = "smtp.live.com ";
SmtpPort = 587;
}
else if (Email.Text.ToLower().Contains("@hotmail.com"))
{
SmtpInfo = "smtp.live.com ";
SmtpPort = 587;
}
MailMessage msg = new MailMessage();
msg.To.Add("USERSEMAIL");
msg.From = new MailAddress(Email.Text);
msg.Subject = "A subject.";
msg.Body = "Hello, this is my message.";
NetworkCredential cred = new NetworkCredential(Email.Text, Password.Text);
SmtpClient client = new SmtpClient(SmtpInfo, SmtpPort);
client.Credentials = cred;
client.EnableSsl = true;
client.Send(msg);
MessageBox.Show("Your message has been sent.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
So basically I want to send an email by using a text command so I would write: sendmail UsersEmail MessageSubject MessageBody
Any help would be great.