Send Email by C# and VB
Aqui está o codigo para enviar email por codigo.
VB code
Imports System.Net.Mail Dim Mail As New MailMessage Dim SMTP As New SmtpClient("smtp.dominio.pt") Dim mailadress1 As String = TextBox1.Text Mail.Subject = "ImasD security code" Mail.From = New MailAddress("software@dominio.pt") SMTP.Credentials = New System.Net.NetworkCredential("software@dominio.pt", "P@ssw0rd") '<-- Password Here Mail.To.Add("npires@dominio.com") 'I used ByVal here for address Mail.To.Add("pedro.falcao@dominio.pt") Mail.Body = send_code & vbCrLf & mailadress1 'Message Here SMTP.EnableSsl = False SMTP.Port = "587" SMTP.Send(Mail) MsgBox("Code generated" & vbCrLf & "You will receive an email with your application code") End Sub
C# Code
using System.Net.Mail;
private void SendEmail() { //MailMessage mail = new MailMessage("you@yourcompany.com", "user@hotmail.com"); MailMessage mail = new MailMessage("ze.falcao@shaymurtagh.ie", "zefalcao@gmail.com"); SmtpClient client = new SmtpClient(); client.Port = 25; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Host = "smtp.gmail.com"; mail.Subject = "this is a test email."; mail.Body = "this is my test email body"; client.Send(mail); }
Comentários
Enviar um comentário