473,503 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in getting email id's separated by comma

3 New Member
Hi,
I'm using VS.Net 2005
and MS Access


I'm using the following code for sending email......
the problem is I've to extract email id's from database and put them in TO or CC field separated with comma when Page is loaded

plz help me in this regard

// message elements
private string mMailServer;
private string mTo;
private string mFrom;
private string mMsg;
private string mSubject;
private string mCC;
private int mPort;



override protected void OnInit(EventArgs e)
{

base.OnInit(e);
btnSend.Click += new System.EventHandler(btnSend_Click);
}

private void MessageBox(string strMsg)
{
Label lbl = new Label();
lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert(" + "'" + strMsg + "'" + ")</script>";

Page.Controls.Add(lbl);

}



protected void btnSend_Click(object sender, System.EventArgs e)
{
string strMsg = null;
strMsg = txtMessage.Text;

System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OleDb.4.0;Data Source=c:/mms.mdb");
con.Open();

mTo = txtTo.Text.Trim(' ');
mFrom = txtFrom.Text.Trim(' ');
mSubject = txtSubject.Text.Trim(' ');
mMsg = txtMessage.Text.Trim(' ');
mMailServer = ConfigurationManager.AppSettings.Get("localhost");
mPort = 25;
mCC = txtCC.Text.Trim(' ');

try
{

MailMessage message = new MailMessage(mFrom, mTo, mSubject, mMsg);

if (fileAttachments.HasFile)
{
Attachment attached = new Attachment(fileAttachments.PostedFile.FileName.ToS tring().Trim(' '));
message.Attachments.Add(attached);
}

if (mCC != "" | mCC != string.Empty)
{
string[] strCC = mCC.Split(';');
foreach (string strThisCC in strCC)
{
message.CC.Add(strThisCC.Trim(' '));
}
}


SmtpClient mySmtpClient = new SmtpClient(mMailServer, mPort);
mySmtpClient.UseDefaultCredentials = true;
mySmtpClient.Send(message);

MessageBox("The mail message has been sent to " + message.To.ToString());

}
catch (FormatException ex)
{

MessageBox("Format Exception: " + ex.Message);

}
catch (SmtpException ex)
{

MessageBox("SMTP Exception: " + ex.Message);

}
catch (Exception ex)
{

MessageBox("General Exception: " + ex.Message);

}

}





In PageLoad I'm currently using the following code


System.Data.OleDb.OleDbConnection con;
System.Data.OleDb.OleDbCommand cmd1;
System.Data.OleDb.OleDbDataAdapter adap;
DataSet ds = new DataSet();


string sql = string.format("select email from emp);
adap = new System.Data.OleDb.OleDbDataAdapter(cmd);
for (I = 0; I < ds.Tables["emp"]. Rows.Count; I++)
{
txtTO.Text = ds.Tables["emp"]. Rows[i]["email"] + ",";
}
May 19 '07 #1
2 1628
shweta123
692 Recognized Expert Contributor
Hi,

Are you getting any error?
Otherwise ,Your code seems to be ok.
You ,can check for the null value of email before this

txtTO.Text = ds.Tables["emp"]. Rows[i]["email"] + ",";.
May 20 '07 #2
KBSK
3 New Member
Hi,

Are you getting any error?
Otherwise ,Your code seems to be ok.
You ,can check for the null value of email before this

txtTO.Text = ds.Tables["emp"]. Rows[i]["email"] + ",";.

Hi, I'm getting Object reference not set to an instance of an object. error in for loop

for (int I = 0; I < ds.Tables["emp"]. Rows.Count; I++)
{
txtTo.Text = ds.Tables["emp"]. Rows[i]["email"] + ",";
}







How to send email to my own system and see it ???
May 20 '07 #3

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

Similar topics

2
14665
by: Alex Hunsley | last post by:
I'm using the smtp module to send emails from python. I would like to specify several recipients of the email like follows: msg = MIMEText(time.ctime("Body text of email") me =...
5
3702
by: dnsstaiger | last post by:
I try to accomplish the following: I have two tables which are connected via a third table (N:N relationship): Table 1 "Locations" LocationID (Primary Key) Table 2 "Specialists"...
3
4837
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
3
1752
by: Karen A Hodge | last post by:
I have a website that has an Excel template. The template contains 3 QueryTables. The template is located on the web server. I would like to refresh the data prior to the user opening the template...
2
1051
by: Tim::.. | last post by:
Can someone please tell me why I keep being redirected back to the login page even though I have logged in with the correct cridentials!!! I have used this code before on another site and it...
1
5294
by: nate axtell | last post by:
In VB .NET I load the contents of an Excel or comma seperated values file into a dataGrid (via a datatable). One of the columns has a comma in the name of the column. So for the comma separated...
0
1375
by: genzy | last post by:
I'm facing the below problem. With <deny users="?" />, the Windows Login ID is able to be obtained to fill up the Windows IDSID text field automatically, but reading the file info is failed. ...
11
2712
by: mohdalibaig | last post by:
the program woks fine for a single record but for multiple records it isn't reading the entries properly... #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<graphics.h> void...
4
7652
by: flavourofbru | last post by:
Hi, In the datagridview control, one of my column has multiple values separated by a comma Is there a way to get individaual values which are separated by a comma from that particular cells? ...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
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
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.