Posts Tagged ‘send mail’

How to send using C# and Google Apps

Posted in General on August 6th, 2010 by Xavier – Be the first to comment

Hi

Some folks have asked me how to send mail from your ASP NET application using Google Apps. Well, it is pretty simple, here is the code that shows you how to do it

MailMessage mm = new MailMessage(new System.Net.Mail.MailAddress(from, “my”), new System.Net.Mail.MailAddress(to));

//Assign the MailMessage’s properties
mm.ReplyTo = new MailAddress(“one@email.com”,”my email”);
mm.IsBodyHtml = isHtml;
mm.Subject = subject;
mm.Body = msg;//”email: ” + UsersEmail.Text + vbCrLf + “Name: ” + UsersName.Text + vbCrLf + “Tel: ” + UsersPhone.Text + vbCrLf + “Mensaje: ” + Body.Text + vbCrLf

//Create the SmtpClient object
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
smtp.Host = “smtp.gmail.com”;
smtp.Credentials = new System.Net.NetworkCredential(user, pwd);

//Send the MailMessage (will use the Web.config settings)
smtp.Send(mm);