try this,
using System.Net.Mail;
using System.Net;
private void SendMail(string targetMail, string shownTargetName, string[] attachmentNames, string Username, string Password, string subject, string body)
{
var fromAddress = new MailAddress("support@gmail.com", "MailSendingPrag");
var toAddress = new MailAddress(targetMail, shownTargetName);
const string fromPassword = "12345isAbadPassword";
subject = "Your Subject";
body = @"Here you can put in" + Username + "and" + Password + "that will appear in the body multilined and even in <html> ";
var smtp = new SmtpClient
{
Host = "smtp.google.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
}
)
{
foreach (string filePath in attachmentNames)
{
Attachment attachMail = new Attachment(filePath);
message.Attachments.Add(attachMail);
}
try
{
smtp.Send(message);
Response.Write("E-Mail sent!");
}
catch
{
Response.Write("Sending failed, check your internet connection!");
}
}
}
password