473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to send email in Asp.Net/C#.Net

Hi all, i need code for sending a mail to different mail ids like a yahoo id ,gmail id etc.whenever i click a button it needs to send a mail to that particular id specified in To: field

My page is like
To: txtto

Subject:txtsubject

Body





send-button
Feb 19 '07 #1
10 4768
enreil
86
Try exploring System.Web.Mail. That makes it pretty simple to generate emails on the fly.

Hi all, i need code for sending a mail to different mail ids like a yahoo id ,gmail id etc.whenever i click a button it needs to send a mail to that particular id specified in To: field

My page is like
To: txtto

Subject:txtsubject

Body





send-button
Feb 19 '07 #2
can u give me code ?
Feb 20 '07 #3
RedSon
5,000 Expert 4TB
can u give me code ?
No, but this can...

http://msdn.microsoft.com/library/de...classtopic.asp
Feb 20 '07 #4
tbarto
19
can u give me code ?
Hi, You can try to do that in the following way:
Expand|Select|Wrap|Line Numbers
  1.     public class Emailer
  2.     {
  3.         #region Variables
  4.  
  5.         private string _smtpServer;
  6.         private string _userName;
  7.         private string _password;
  8.         private ArrayList _recipients;
  9.  
  10.         #endregion
  11.  
  12.         #region Constructors
  13.  
  14.         public Emailer()
  15.         {
  16.  
  17.         }
  18.  
  19.         #endregion
  20.  
  21.         #region Properties
  22.  
  23.         public string SmtpServer
  24.         {
  25.             set
  26.             {
  27.                 _smtpServer = value;
  28.             }
  29.         }
  30.  
  31.         public string UserName
  32.         {
  33.             set
  34.             {
  35.                 _userName = value;
  36.             }
  37.         }
  38.  
  39.         public string Password
  40.         {
  41.             set
  42.             {
  43.                 _password = value;
  44.             }
  45.         }
  46.  
  47.         public ArrayList Receipients
  48.         {
  49.             set
  50.             {
  51.                 _recipients = value;
  52.             }
  53.         }
  54.  
  55.         #endregion
  56.  
  57.         #region Methods
  58.  
  59.         public void SendMessage(string subject, string content)
  60.         {
  61.             string domain = "";
  62.  
  63.             if (_smtpServer.Substring(0, 5).ToLower().Equals("smtp."))
  64.                 domain = _smtpServer.Substring(5, _smtpServer.Length - 5);
  65.             else
  66.                 domain = _smtpServer;
  67.  
  68.             string recipient = _userName.ToLower();
  69.             MailMessage _mail = new MailMessage();
  70.  
  71.  
  72.             try
  73.             {
  74.  
  75.                 System.Net.Mail.MailAddress _from = new System.Net.Mail.MailAddress(recipient + "@" + domain, recipient);
  76.                 System.Net.Mail.MailAddressCollection addresses = new System.Net.Mail.MailAddressCollection();
  77.  
  78.                 _mail.From = _from;
  79.                 _mail.Subject = subject;
  80.                 _mail.Body = content;
  81.                 _mail.Priority = System.Net.Mail.MailPriority.High;
  82.  
  83.  
  84.             }
  85.             catch (Exception)
  86.             {
  87.                Do something...
  88.             }
  89.  
  90.             try
  91.             {
  92.  
  93.                 foreach (string adress in _recipients)
  94.                 {
  95.                     MailAddress addr = new MailAddress(adress);
  96.  
  97.                     if (!_mail.To.Contains(addr))
  98.                         _mail.To.Add(addr);
  99.                 }
  100.             }
  101.             catch (Exception)
  102.             {
  103.                Do something
  104.             }
  105.  
  106.  
  107.  
  108.             try
  109.             {
  110.                 System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(_smtpServer);
  111.                 smtp.Credentials = new System.Net.NetworkCredential(_userName, _password);
  112.  
  113.                 smtp.Send(_mail);
  114.             }
  115.             catch (Exception)
  116.             {
  117.                 do something
  118.             }
  119.  
  120.             _mail.Dispose();
  121.  
  122.         }
  123.  
  124.         #endregion
  125.  
  126.     }
  127.  
Feb 20 '07 #5
RedSon
5,000 Expert 4TB
First, you need to put CODE tags around your code, it is very annoying to read your post with out them. Second, it is better to let others work through their problems with guidance instead of giving them the entire solution. Your solution will likely not meet their needs, and further more they should be familiar with how to send an email using the asp.net classes. I wish I could edit your post so that it was easier to read, but I can't. If you still can, you should!
Feb 20 '07 #6
tbarto
19
First, you need to put CODE tags around your code, it is very annoying to read your post with out them. Second, it is better to let others work through their problems with guidance instead of giving them the entire solution. Your solution will likely not meet their needs, and further more they should be familiar with how to send an email using the asp.net classes. I wish I could edit your post so that it was easier to read, but I can't. If you still can, you should!
Hi

Since I am a new at this forum, please forgive me all the mistakes. Thank You for Your advices. I will follow them in the future.
Sorry, I am not able to edit my previous post anymore.
Feb 20 '07 #7
RedSon
5,000 Expert 4TB
No problem, just remember the CODE tags, it is a real pet peeve of mine!
Feb 20 '07 #8
GNoter
9
Expand|Select|Wrap|Line Numbers
  1. Protected Sub TestCode(ByVal sTemp as string)
  2.   If sTemp.Length = 0 then 'no data in variable.
  3.  
  4.   End if
  5. End Sub
  6.  
(just testing the CODE tags; above code is merely test code.
Feb 20 '07 #9
AricC
1,892 Expert 1GB
First, you need to put CODE tags around your code, it is very annoying to read your post with out them.
I edited and added code tags.
Feb 20 '07 #10
enreil
86
Well said, RedSon, I agree.

First, you need to put CODE tags around your code, it is very annoying to read your post with out them. Second, it is better to let others work through their problems with guidance instead of giving them the entire solution. Your solution will likely not meet their needs, and further more they should be familiar with how to send an email using the asp.net classes. I wish I could edit your post so that it was easier to read, but I can't. If you still can, you should!
Feb 20 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Google Mike | last post by:
I've got RH9 Linux with default PHP. Is there a way to send email on Linux to an Exchange Server from PHP and/or other tools when there is *NOT* SMTP access? Has anyone figured out a way to...
40
by: ian | last post by:
Hi, I'm a newbie (oh no I can here you say.... another one...) How can I get Python to send emails using the default windows email client (eg outlook express)? I thought I could just do the...
0
by: David Burson | last post by:
Hi, I have a VB.NET windows app that needs to automatically send a simple text email when my users run a new version of the app for the first time. I thought this would be simple, but after...
9
by: Bob Jones | last post by:
We have developed a commercial ASP.net application (personal nutrition management and tracking); we want to send smtp email from within it. For our development box, we use WinXP Pro, IIS 5.5,...
3
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
14
by: supz | last post by:
Hi, I use the standard code given below to send an email from an ASP.NET web form. The code executes fine but no Email is sent. All emails get queued in the Inetpub mail queue. I'm using my...
8
by: shapper | last post by:
Hello, I am trying to send an email using Asp.Net 2.0. I am getting the following error: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: No such...
9
by: Mahernoz | last post by:
Can i send an email from JavaScript? Is it possible? If yes please the code to send email using javascript...
2
by: Malli mindwave | last post by:
Hi, We are using the yahoowebHostiing service for my company website, In that one screen of the SendComments/FeedBack section is there, I'm basically dot.net develeoper ,but yahoowebhosting not...
5
by: Mike | last post by:
I have a page with a textbox that a user can enter in mutliple email addresses such as: user1@yahoo.com;user2@yahoo.com;user3@gmail.com; and so on, I then have a foreach loop to get all of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.