Send MMS From C#

8 Apr
The Best GUI you have ever seen.

The Best GUI you have ever seen.

I have been working on ArcGIS Desktop Explorer writing a few plugins. One of them was to send a text message. Sending text messages just requires an email to be sent to the appropriate gateway. These gateways differ for SMS and MMS. For a list of gateways go to Wikipedia. Here is the code to send an MMS in C#.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;

namespace MMS
{
    public partial class Form1 : Form
    {
        private String strFileName = string.Empty;

        public Form1()
        {
            InitializeComponent();
        }

        private void sendbtn_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient(“Your.SMTP.Server”);
                mail.From = new MailAddress(YourEMail@Domain.com);
                mail.To.Add(tobox.Text.ToString());
                mail.Subject = subjbox.Text.ToString();
                mail.Body = msgbox.Text.ToString();

                System.Net.Mail.Attachment attachment;
                attachment = new System.Net.Mail.Attachment(strFileName);
                mail.Attachments.Add(attachment);

                SmtpServer.Send(mail);
                MessageBox.Show(“Sent Message”,”MMS by Paul”);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

        private void attachbtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = “All files (*.*)|*.*”;
            openFileDialog1.InitialDirectory = “C:”; openFileDialog1.Title = “Select an Attachment”;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
                strFileName = openFileDialog1.FileName;
            if (strFileName == String.Empty)
                 return;//user didn’t select a file

         }

     }
}

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: