Visual Studio .NET - SMTP mail

Asked By rama bala
11-Aug-09 03:03 AM
how to code to connect SMTP and send mail

RE  RE

11-Aug-09 03:08 AM
Hi

You can do liek this way to send email and connect to SMTP

1. you need know IP address of the SMTP
2. username and password for the access the SMTP

/// <summary></summary><summary></summary>
/// send email from the asp.net with file attachment.
/// <summary></summary><summary></summary>
private void SendEmail()
{
try
{
MailMessage message = new MailMessage();
//from address
message.From = new MailAddress("fromEmailAddress", "Messsage");
// to address
message.To.Add(new MailAddress("ToEmailAddress", "The CodeGain Info"));

// set content email
message.Body = "This is auto generated email dont reply and you have two attachements also";
//set this email content display user inbox like Html format
message.IsBodyHtml = true;

// this is the heading of the email
message.Subject = "The CodeGain.com Message";



SmtpClient emailClient = new SmtpClient("serverIP", 25);// 25 is default for SMTP server
emailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
// set users to default use the default credential
emailClient.UseDefaultCredentials = true;

emailClient.Send(message);
}
catch (SmtpException smtpex)
{
throw smtpex;
}
catch (Exception ex)
{

throw ex;
}


}

Note:Just call this method in your button click or where you need.

more detail can see http://www.codegain.com/index.php?option=com_content&view=article&id=109:send-email-in-aspnet-with-attachment&catid=62:miscellaneous
Thank you
http://www.codegain.com

Reply for mail  Reply for mail

11-Aug-09 03:09 AM

please use this code ur problem will shortout

 

#region sendMail()

public string sendMail(string to, string from, string subject, string mails, string msgs)

{

string messages = msgs;

SmtpClient objMail = new SmtpClient();

MailAddress SendFrom = new MailAddress(from);

MailAddress SendTo = new MailAddress(to);

MailMessage msg = new MailMessage(SendFrom, SendTo);

//msg.Bcc.Add("raghv.singh@magnonsolutions.com");

msg.Subject = subject;

msg.IsBodyHtml = true;

msg.Priority = MailPriority.High;

string mailbody = mails;

msg.Body = mailbody;

try

{

objMail.Send(msg);

}

catch (Exception exc)

{

messages = "Send failure: <br>" + exc.Message;

}

return messages;

}

#endregion

re  re

11-Aug-09 03:14 AM
This code snippet works well for me -

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

System.Net.NetworkCredential cred = new System.Net.NetworkCredential("yourid@gmail.com", "yourpwd");

mail.To.Add("acme@acme.com");
mail.Subject = "subject";

mail.From = new System.Net.Mail.MailAddress("yourid@gmail.com");
mail.IsBodyHtml = true;
mail.Body = "message";

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Credentials = cred;
smtp.Port = 587;
smtp.Send(mail);


http://mvark.blogspot.com/2006/09/sending-mail-programmatically-using-c.html
SMTP mail  SMTP mail
11-Aug-09 03:35 AM
If you are using .NET 2.0 Framework & above, the classes in System.Net.Mail namespace can help you out. If you need to support the 1.x .NET Framework, you would have to use the System.Web.Mail namespace.

For a simple example of sending mail using System.Net.Mail, check this link -
http://systemnetmail.com/faq/3.1.1.aspx

and to do the same with 1.x .NET Framework, , check this link -
http://www.systemwebmail.com/faq/2.1.aspx

For the most comprehensive info with example on sending mails using System.Net.Mail & System.Web.Mail, check the FAQs at these links -
http://systemnetmail.com/
http://www.systemwebmail.com/
Create New Account
help
Visual Studio .net .NET Framework Hi NG, ich habe vor längerer Zeit mit Visual Studio .Net 2003 gearbeitet und überlege momentan auf einen neueren Stand upzudaten. Ein Visual Studio .Net 2008 scheint es nicht zu geben. Habe zumindest mit googeln nichts gefunden. Was
Visual Studio versioning . . . . how to tell? .NET Framework To my knowledge, Visual studio 6 was released in 1998, then Visual Studio .NET 2002 is VS 7, then Visual Studio .NET 2003 is VS 7.1, then Visual
visual studio.net 2003 and Access 2007 database .NET Framework Hi I am currently using Visual Studio.Net 2003 running on Windows Server 2000 operating system. I have used Visual Studio.net 2003 connecting to Access 2002 databases in the pass with great success. Now
Is Visual Studio self-hosting ? .NET Framework Does Microsoft use Visual Studio IDE, Visual Studio Debugger, Visual Studio Linker and Visual Studio compiler for developing Visual Studio ? Or is Visual Studio not
Wise for Visual Studio.NET Wise for Visual Studio.NET By Peter A. Bromberg, Ph.D. To "Print This Page" Link Peter Bromberg Wise for Visual Studio .NET is a total and complete installation development system for creating and editing Windows® Installer