none
WinForm move data to an email RRS feed

  • Question

  • Afternoon All

    I am hoping someone can help.

    Im currently trying to programme a form so data can be entered and then sent via email (at the moment i want it sending via Outlook). I have created the form and have a submit button - this seems to be working however i cant figure out how to pull the data through. 

    On my form i have the following

    -> 7 textbox boxes

    -> 1 combo box

    -> 8 Labels

    In theory i would like the email to say something like

    Please see below the following new user information:

    Firstname: ........(textBox1)

    Surname: ..........(textBox2)

    Username: .........(textBox 3) etc etc.

    The code i have is below.  Thanks in advance

    Im also trying to pull information from certain textboxes to be displayed in the Subject Line. ie. Subject: New User Information - Surname

    (Surname would come from textBox3 on the form)

    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 MetroFramework.Forms;
    using Microsoft.Office.Interop.Outlook;
    
    namespace NewUserEmailTemplate
    {
        public partial class Form1 : MetroForm
        {
            public Form1()
            {
                InitializeComponent();
                this.AutoValidate = System.Windows.Forms.AutoValidate.Disable;
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                metroTextBox1.Focus();
            }
    
            private void metroButton2_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void metroButton3_Click(object sender, EventArgs e)
            {
                this.ClearAllFields(this);
            }
    
            private void ClearAllFields(Control control)
            {
                foreach (Control c in control.Controls)
                {
                    var box = c as TextBox;
                    if (box !=null)
                    {
                        box.Text = string.Empty;
                    }
    
                    this.ClearAllFields(c);
                }
    
                metroComboBox1.SelectedItem = null;
                
            }
    
            private void metroTextBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
                {
                    e.Handled = true;
                }
            }
    
            private void metroTextBox6_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
                {
                    e.Handled = true;
                }
            }
    
            private void metroButton1_Click(object sender, EventArgs e)
            {
                if (this.ValidateChildren(ValidationConstraints.Enabled))
                {
                    Microsoft.Office.Interop.Outlook.Application oapp = new Microsoft.Office.Interop.Outlook.Application();
                    Microsoft.Office.Interop.Outlook.MailItem omsg = (Microsoft.Office.Interop.Outlook.MailItem)oapp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
    
                    //subject line
                    omsg.Subject = "User New Network Account Request -"; 
    
                    //body of email
             //       omsg.Body = "Please see the following New User Request" "<br />"
                    
                    omsg.Body = metroTextBox2.Text + "<br />"
                        + metroTextBox3.Text + "<br />"
                        + metroTextBox4.Text;
                        
    
    
                  
                    
                    
                    
    
                    //display message in outlook
                    omsg.Display();
                }
    
                else
                {
                    MessageBox.Show("There are missing fields on this form!");
                }
            }
    
            private void metroTextBox4_Validating(object sender, CancelEventArgs e)
            {
                bool cancel = false;
                if (string.IsNullOrEmpty(this.metroTextBox4.Text))
                {
                    cancel = true;
                    this.errorProvider1.SetError(this.metroTextBox4, "You must provide a username!");
                }
    
                e.Cancel = cancel;
            }
    
            private void metroTextBox5_Validating(object sender, CancelEventArgs e)
            {
                bool cancel = false;
                if (string.IsNullOrEmpty(this.metroTextBox5.Text))
                {
                    cancel = true;
                    this.errorProvider1.SetError(this.metroTextBox5, "You must provide a valid email address!");
                }
    
                e.Cancel = cancel;
            }
            }
    
            
            }
    
    
            
        




    • Edited by LloydyJ89 Monday, March 19, 2018 3:40 PM
    • Moved by Stanly Fan Tuesday, March 20, 2018 6:17 AM
    Monday, March 19, 2018 3:33 PM

All replies

  • Hi LloydyJ89,

    Since your project is used 3rd reference, it will be more appropriate to ask your question at Syncfusion Windows Forms Forum.

    Thank you for your understanding.

    Regards,

    Frankie

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 20, 2018 6:14 AM