You must Sign In to post a response.
Category: .NET
#768337
Hi,
We have huge number of examples for sending mail using C# applications.
Basically we need SMTP to sent this mail to anywhere from the application.
Initially we need to add Libraries to make it work.
The SMTP server should be maintained and configured.
The remaining codings will be the configuring of the mails like From,To and subjects etc.
Finally we can send the mail with send() option in s SMTP.
Thanks,
Mani
We have huge number of examples for sending mail using C# applications.
Basically we need SMTP to sent this mail to anywhere from the application.
Initially we need to add Libraries to make it work.
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
The SMTP server should be maintained and configured.
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.google.com"); // Any server as you preferred
The remaining codings will be the configuring of the mails like From,To and subjects etc.
mail.From = new MailAddress("123@gmail.com");
mail.To.Add("321@gamil.com");
mail.Subject = Testing Application ;
mail.Body = "Check the Report";
Attachment attachment = new Attachment(filename);
mail.Attachments.Add(attachment);
Finally we can send the mail with send() option in s SMTP.
SmtpServer .Send(mail);
Thanks,
Mani
#768346
You can use given code snippet to send email using Gmail account and Gmail SMTP server in ASP.Net
protected void SendEmail(object sender, EventArgs e)
{
using (MailMessage mm = new MailMessage(txtEmail.Text, txtTo.Text))
{
mm.Subject = txtSubject.Text;
mm.Body = txtBody.Text;
if (fuAttachment.HasFile)
{
string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
}
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text, txtPassword.Text);
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Your Email sent.');", true);
}
}
More useful reference: http://stackoverflow.com/questions/18326738/how-to-send-email-in-asp-net-c-sharp
http://www.codeproject.com/Tips/371417/Send-Mail-Contact-Form-using-ASP-NET-and-Csharp
Return to Return to Discussion Forum