Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: c# splitting string into separate strings.  (Read 9595 times)

0 Members and 1 Guest are viewing this topic.

DaftHacker

    Topic Starter


    Rookie

  • I am Daft
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 8
c# splitting string into separate strings.
« on: May 26, 2013, 04:09:00 AM »
Hello all im trying to split a string into multiple strings for instance im trying to send an email with a string.

Code: [Select]
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.

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: c# splitting string into separate strings.
« Reply #1 on: May 26, 2013, 06:41:49 AM »
Split on another character.
I was trying to dereference Null Pointers before it was cool.