I need to make a mailing script. It needs to mail a certain string to me and save the string as a file. The saving part works but the mailing parts seem to fail? Could someone please tell me what I'm doing wrong here?
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;
using System.Net.Mail;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void username_TextChanged(object sender, EventArgs e)
{
}
private void userplot_TextChanged(object sender, EventArgs e)
{
}
private void userreason_TextChanged(object sender, EventArgs e)
{
}
private void sendrequest_Click(object sender, EventArgs e)
{
string user = username.Text;
string plot = userplot.Text;
string reason = userreason.Text;
string all = user + " - " + plot + " - " + reason;
System.IO.File.CreateText (all);
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.Subject = "Test Mail - 1";
mail.Body = all;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "**********"); SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}