Email That Works!

Protected Sub SendEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendEmail.Click

Dim mm As New Net.Mail.MailMessage("sales@email.co.uk", SendTo.Text) 'sendto.text textbox

mm.Subject = Subject.Text 'textbox

mm.Body = Body.Text 'textbox

mm.IsBodyHtml = False

Dim smtp As New Net.Mail.SmtpClient

smtp.Host = "smtp.email.co.uk"

smtp.Credentials = New Net.NetworkCredential("sales@email.co.uk", "saxxxxxn")

smtp.Send(mm)

End Sub



Answer this question

Email That Works!

  • Michael A. Riley

    C# translation:

    //import the System.Net/System.Net.Mail namespace:

    using System.Net.Mail;

    ..

    ..



    //some event example: button click:
     
    MailMessage theMailMessage = new MailMessage("email@address.com", "to@someAddress.com");
    theMailMessage.Subject = "Your subject";
    theMailMessage.Body = "the body email message";
     
    //to enable html formatting, uncomment this line:
    //theMailMessage.IsBodyHtml = true; //by default its false
     
    //add attachments:
    theMailMessage.Attachments.Add(new MailAttachment("pathToFile"));
     
    try
    {
       SmtpClient theSmtpServer = new SmtpClient("some.Smtp.Ip.Address");
       theSmtp.Credientials = new NetworkCredential("your@emailAddress.com", "password");
       theSmtpServer.Send(theMailMessage);
    }
    catch (SmtpException ex)
    {
       //handle the error
    }

     



  • Email That Works!