Please Note that I have changed address
Go to
Baking Ways / Productive Bytes

Search This Blog


Monday, November 15, 2010

How to send a mail message in C#

Here you can find a piece of code to send mail using c#.
Please not that you need to know your Smtp Host server name to be able to sent out any mail.
In addtion I added a couple of lines to get the current user name.
You can map the current user name to an email address so that you can send the mail out from the current user mail address

ex: mailAddress = abeti then use as mail address

using System.Net.Mail;
using System.Security.Principal;

private void button1_Click(object sender, EventArgs e)

string mailAddress;
mailAddress = WindowsIdentity.GetCurrent().Name;
MailMessage message = new MailMessage();
message.From = new MailAddress("");
message.To.Add(new MailAddress(""));
message.CC.Add(new MailAddress(""));
message.Subject = "Message From .Net";
message.Body = "This is the content";
string pdfPath = "C:\\test\\";
string pdfFileName = "prova.pdf";
Attachment pdfFile = new Attachment(pdfPath + pdfFileName);
SmtpClient client = new SmtpClient();

No comments:

Post a Comment