smtp to send mail using c#

Posted by Raj_Chennai under ASP.NET on 3/15/2012 | Points: 10 | Views : 11630 | Status : [Member] | Replies : 14
coding in c# for using smtp to send email

raj


Responses

Posted by: CGN007 on: 3/15/2012 [Member] Silver | Points: 25

Up
0
Down
Please refer the following links
http://www.dotnetfunda.com/forums/thread8293-sending-mail-in-csharp-using-smtp-client.aspx
http://www.systemnetmail.com/
http://www.codeproject.com/Articles/13690/Sending-SMTP-mail-from-ASP-NET-and-codebehind-as-C

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/15/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi try this code, i test this code, its working

SmtpClient client = new SmtpClient("smtp.mail.yahoo.com", 25);
MailMessage mail_msg = new MailMessage();

MailAddress fromAdd = new MailAddress(tbFrom.Text.Trim()); //hmanjarawala@yahoo.com
mail_msg.From = fromAdd;
mail_msg.To.Add(new MailAddress(tbTo.Text.Trim())); //hmanjarawala@gmail.com
mail_msg.Subject = tbSubject.Text;
mail_msg.IsBodyHtml = true;
mail_msg.Body = "Message From: " + tbFrom.Text.Trim() + "Subject:" + tbSubject.Text.Trim() + "Email: " + tbTo.Text.Trim() + "Content: " + tbContent.Text.Trim();

System.Net.NetworkCredential basicCredential = new System.Net.NetworkCredential("hmanjarawala@yahoo.com", "***********");
client.EnableSsl = false;
client.UseDefaultCredentials = true;
client.Credentials = basicCredential;
client.Send(mail_msg);


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 3/15/2012 [Member] Starter | Points: 25
Posted by: Sksamantaray on: 3/15/2012 [Member] Silver | Points: 25

Up
0
Down
Hi,
Can use following code to send Smtp Mail


using System.Net.Mail



// message.Attachments.Add(new Attachment(@"C:\Data.txt"));
SmtpClient smtpClient = new SmtpClient("220.225.30.220");
MailMessage message = new MailMessage("sanjaya@mail.direct-services.com", "<sanjaya_samantaray@yahoo.co.in>,<sanjaya_samantaray@rediffmail.com>");
message.Subject = "Subject Email";
message.Body = "Sanjay here testing mail.....";
message.IsBodyHtml = true;
message.Attachments.Add(new Attachment(@"C:\Data.txt"));
///smtpClient.Credentials = new NetworkCredentials("sender@sender.com", "password");
smtpClient.Send(message);


Thanks,
Sanjay

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 4/3/2012 [Member] Starter | Points: 25

Up
0
Down
http://sandeep-chourasia.blogspot.in/2011/05/send-mail-in-aspnet.html

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/29/2012 [Member] Silver | Points: 25

Up
0
Down
Mark as Answer if it helpful to you,that motivates...

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muralidosscm on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down
using System.Net;
using System.Net.Mail;
OpenFileDialog dlg = new OpenFileDialog();
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
string filename = dlg.FileName;

try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

mail.From = new MailAddress("me@mydomain.com");
mail.To.Add("u@urdomain.com");
mail.Subject = filename;
mail.Body = "Report";
Attachment attachment = new Attachment(filename);
mail.Attachments.Add(attachment);

SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential("me", "password");
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);
}

Regards
Muralidoss M

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/10/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Refer this URL.
http://www.codeproject.com/Tips/371417/Send-Mail-Contact-Form-using-ASP-NET-and-Csharp

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/10/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" );

MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
MailMessage newmsg = new MailMessage ( mailfrom, mailto );
newmsg.Subject = "Subject of Email";
newmsg.Body = "Body(message) of email";
////For File Attachment, more file can also be attached
Attachment FileAtt= new Attachment ( "File Location" );
newmsg.Attachments.Add ( FileAtt);
SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
smtps.UseDefaultCredentials = false;
smtps.Credentials = new NetworkCredential ( "urmailID@gmail.com", "urpwd" );
smtps.EnableSsl = true;
smtps.Send ( newmsg );


Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 7/31/2012 [Member] Silver | Points: 25

Up
0
Down
Mark as answer if it helps...,That motivates...!!!

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/31/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
hi one more link. plz chk
http://www.dotnetfunda.com/codes/code2916-send-mail-in-csharp.aspx

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Calvert on: 8/1/2012 [Member] Starter | Points: 25

Up
0
Down
Ensure you've registered cdosys.dll properly. Also, if you're running SMTP on a local box, use 'localhost' as the SMTP server. Those are the only issues I experienced when running this sample application. ~~cj
http://www.dapfor.com/en/net-suite/net-grid/tutorial/data-binding


Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumaran1987 on: 1/25/2013 [Member] Starter | Points: 25

Up
0
Down
See this article link will help you !!!

How to Send Email (Gmail) using ASP.NET C# SmtpClient?
http://www.kumaran198726.com/2013/01/how-to-send-email-gmail-using-aspnet-c.html

Kumaran K

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/25/2013 [Member] Starter | Points: 25

Up
0
Down
use this code
using System.Net.Mail;


using System.Data.SqlClient;



public partial class complaint_form : System.Web.UI.Page

{

dbClass db = new dbClass();

protected void Page_Load(object sender, EventArgs e)

{



}

protected void Button1_Click(object sender, EventArgs e)

{

db.myconnection();

MailMessage msg = new MailMessage();

msg.From = new MailAddress("recipientmailid@rediffmail.com");

msg.To.Add("recipientmailid@india.com");

msg.Subject = TextBox3.Text;

msg.Body = "sender name:" + TextBox1.Text + "<break>sender email:" + TextBox2.Text + "<break>sender subject:" + TextBox3.Text + "<break>sender body:" + TextBox4;

SmtpClient smtp=new SmtpClient();

smtp.Host ="smtp.gmail.com";

smtp.Port=587;

smtp.Credentials =new System.Net .NetworkCredential("uremailid@gmail.com", "ur password");

smtp.EnableSsl =true ;

smtp.Send(msg);





}

}


Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response