i am trying to send an email, and the email address is from the SQL DB
example of my data in my DB is:
email1@mail.com, email2@mail.com
but when i send the email through my ASP.NET app, it only sends to email2@mail.com
the data type is nvarchar(max)
how can i fix this? thanks!
UPDATE
public void emailtoPIC()
{
SmtpClient smtpClient = new SmtpClient();
NetworkCredential NetworkCred = new NetworkCredential("online.****@ph.yusen-logistics.com", "****");
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = NetworkCred;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Host = "17*.*.*.**";
smtpClient.Port = **;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("online.****@ph.yusen-logistics.com", "****Online Travel Request");
mail.CC.Add(new MailAddress(hidePICemail.Text));
mail.Subject = "[Travel Order]" + TravelNumber.Text + " - For Processing";
mail.Body = "<html>" +
"<body>" +
"<style>" +
"p {" +
"font-size:15px;" +
"color:black;" +
"font-family: Calibri" +
"}" +
"</style>" +
"<p>Greetings </p>" +
"<p>You have a Travel Request for Processing</p>" +
"<p>Travel Request Number: <b>" + TravelNumber.Text + "</b></p>" +
"<p> Date/Time Filed: <b>" + DateValue.Text + "</b></p>" +
"<p>Please see below details </p>" +
"<hr align='left' width='50%'>" +
"<p>Name of Traveler: <b>" + txtName.Text + "</b></p>" +
"<p>Business Unit: <b>" + ddlBU.SelectedItem.Text + "</b></p>" +
"<p>Department: <b>" + ddlDept.SelectedItem.Text + "</b></p>" +
"<p>Type of Travel: <b>" + ddlType.SelectedItem.Text + "</b></p>" +
"<p>Destination: <b>" + txtDesti.Text + "</b></p>" +
"<p>Purpose of Travel: <b>" + ddlPurpose.SelectedItem.Text + "</b></p>" +
"<p>Details: <b>" + txtDetails.Text + "</b></p>" +
"<p>Preferred Departure: <b>" + txtDepDate.Text + "</b></p>" +
"<p>Preffered Return: <b>" + txtRetDate.Text + "</b></p>" +
"<p>Flight Time (ETD / ETA): <b>" + txtFlight.Text + "</b></p>" +
"<p>Booking PIC: <b>" + txtPIC.Text + "</b></p>" +
"<p>Remarks: <b>" + txtRemarks.Text + "</b></p>" +
"<p>Approver 1: <b>" + ddlapp1.SelectedItem.Text + "</b></p>" +
"<p>Approver 2: <b>" + ddlapp2.SelectedItem.Text + "</b></p>" +
"<p>Status: <b>" + txtStatus.Text + " </b></p>" +
"<p><a href ='http://172.20.3.24/Yusen/TOR/ProcessRequests.aspx'>Click here to process the request</a></p>" +
"</body>" +
"</html>";
mail.IsBodyHtml = true;
try
{
smtpClient.Send(mail);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
Response.Write("<script>alert('Sending failed..')</script>");
}
}
hidePICEmail is from my DB where i store multiple email in one column.
You need to add each To email address to MailMessage. You can do something like this.
List<string> emailTo = new List<string>();
emailTo.AddRange(receiverEmail.Split(',').ToList<string>()); // Create a list of To Addresses
using (MailMessage message = new MailMessage())
{
message.From = new MailAddress(emailFrom);
// Add each to address
foreach (string EmailId in emailTo)
{
message.To.Add(new MailAddress(EmailId));
//message.CC.Add(new MailAddress(EmailId)); // You can do the same thing for CC email
}
message.Subject = emailSubject;
message.IsBodyHtml = true;
message.Body = messageBody;
SmtpClient client = new SmtpClient();
client.Host = smtpHost;
client.Port = Convert.ToInt32(smtpPort);
client.Send(message);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.