So I wanted to try and send my self some mail using a Visual C# application but it seems to just run through the code (I know this because I put a message box at the end of the code) and not send anything. I did change the email information below for obvious reasons.
Here’s what I have:
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;
using System.Net;
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string Host = "smtp.live.com";
Int16 Port = 587;
bool SSL = true;
string Username = "myemail@hotmail.com";
string Password = "mypassword";
// Mail options
string To = "myemail@hotmail.com";
string From = "email@hotmail.com";
string Subject = "This is a test";
string Body = "It works!";
MailMessage mm = new MailMessage(From, To, Subject, Body);
SmtpClient sc = new SmtpClient(Host, Port);
NetworkCredential netCred = new NetworkCredential(Username, Password);
sc.EnableSsl = SSL;
sc.UseDefaultCredentials = false;
sc.Credentials = netCred;
MessageBox.Show("Test");
}
}
}
*Note, I get NO errors from this.
You don’t actually send the mail.
Add this to your code – you should be able to figure out where: