MailMessage oMsg = new MailMessage();
// TODO: Replace with sender e-mail address.
oMsg.From = "
[email protected]";
// TODO: Replace with recipient e-mail address.
oMsg.To = "
[email protected]";
oMsg.Subject = "Send Using Web Mail";
// SEND IN HTML FORMAT (comment this line to send plain text).
oMsg.BodyFormat = MailFormat.Html;
// HTML Body (remove HTML tags for plain text).
oMsg.Body = "<HTML><BODY><B>Hello World!</B></BODY></HTML>";
// ADD AN ATTACHMENT.
// TODO: Replace with path to attachment.
//String sFile = @"C:\temp\Hello.txt";
//MailAttachment oAttch = new MailAttachment(sFile, MailEncoding.Base64);
//oMsg.Attachments.Add(oAttch);
// TODO: Replace with the name of your remote SMTP server.
SmtpMail.SmtpServer = "server...";//stavim pod komentar da bi slao default ali NEĆE ??????
SmtpMail.Send(oMsg);
oAttch = null;
oMsg = null;
//TREBALO BI SADA DA RADI - moras da unistis oMsg i oAttch kao sto zatvaras streamreader i writer za pisanje i citanje fajlova !
ILI PROBAJ OVO >
private void sentbtn_Click(object sender, EventArgs e)
{
try
{
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
mail.From = fromtxt.Text;
if (fromtxt.Text == String.Empty)
{
statuslb.Items.Add("Error : From who is missing.");
}
else
{
statuslb.Items.Add("From : " + fromtxt.Text);
}
mail.To = totxt.Text;
if (totxt.Text == String.Empty)
{
statuslb.Items.Add("Error : To who is missing.");
}
else
{
statuslb.Items.Add("To : " + totxt.Text);
}
mail.Subject = subjecttxt.Text;
if (subjecttxt.Text == String.Empty)
{
statuslb.Items.Add("Error : Subject is missing");
}
else
{
statuslb.Items.Add("Subject: " + subjecttxt.Text);
}
mail.BodyFormat = MailFormat.Text;
statuslb.Items.Add("Mail format : text");
mail.Body = bodyrtxt.Text + "\n\n\n(IQooLogic.NT.018 mail Client)mail:
[email protected]\nBuilt by IQooLogic.NT.018 All rights reserved.\nNIS 4Ever!!!";
if (fatt != String.Empty)
{
MailAttachment att = new MailAttachment(fatt, MailEncoding.Base64);
mail.Attachments.Add(att);
SmtpMail.SmtpServer = smtpcombo.Text;
statuslb.Items.Add("SMTP :" + smtpcombo.Text);
SmtpMail.Send(mail);
statuslb.Items.Add("******************SENT******************");
errbtn.BackColor = Color.Lime;
Cursor.Current = cr;
att = null;
}
else
{
statuslb.Items.Add("Attachment : none");
SmtpMail.SmtpServer = smtpcombo.Text;
statuslb.Items.Add("SMTP :" + smtpcombo.Text);
SmtpMail.Send(mail);
statuslb.Items.Add("******************SENT******************");
errbtn.BackColor = Color.Lime;
Cursor.Current = cr;
}
mail = null;
}
catch (Exception err)
{
errbtn.BackColor = System.Drawing.Color.Red;
statuslb.Items.Add("Error : " + err.Message);
statuslb.Items.Add("*********************ERROR*********************");
}
}