Sending Email using net.mail

Hi,

I have an email class using net.mail. I want to be able to send multiple emails for weekly newsletters. I add recipients using AddRecipeint method then build the recipient list using BuildRecipientList(). This all works fine, however the problem is that each email displays all recipients in the To: address list. Obviously I only want to have the recipients email shown. Can anyone tell me how to hide all other recipients except the reciever or if there is a better way of sending to multiple users?

        public void AddRecipient(string EmailAddress)
        {
            arToAddresses.Add(EmailAddress);
        }

         private void BuildRecipientList(MailMessage Mailer)
        {
            foreach (string s in arToAddresses)
            {
                Mailer.To.Add(new System.Net.Mail.MailAddress(s));
            }
        }

         BuildRecipientList(Mailer);

 

Thanks in advance!! 

Chris 

0
ChrisSOTM
7/10/2008 8:00:51 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

3 Replies
715 Views

Similar Articles

[PageSpeed] 19

Add recepients to the BCC (blind carbon copy) field instead of TO. Just replace Mailer.To.Add with the Mailer.Bcc.Add

0
Klev
7/10/2008 8:44:22 PM
Cheers Klev, never thought to use BCC, but now so obvious, thanks.
0
ChrisSOTM
7/10/2008 9:10:32 PM

Hi

try this example:

create class in App_Code

MailHelper.cs

using System.Net.Mail;

public class MailHelper
{
    /// <summary>
    /// Sends an mail message
    /// </summary>
    /// <param name="from">Sender address</param>
    /// <param name="to">Recepient address</param>
    /// <param name="bcc">Bcc recepient</param>
    /// <param name="cc">Cc recepient</param>
    /// <param name="subject">Subject of mail message</param>
    /// <param name="body">Body of mail message</param>
    public static bool SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
    {
        // Instantiate a new instance of MailMessage
        MailMessage mMailMessage = new MailMessage();

        // Set the sender address of the mail message
        mMailMessage.From = new MailAddress(from);
        // Set the recepient address of the mail message
        mMailMessage.To.Add(new MailAddress(to));

        // Check if the bcc value is null or an empty string
        if ((bcc != null) && (bcc != string.Empty))
        {
            // Set the Bcc address of the mail message
            mMailMessage.Bcc.Add(new MailAddress(bcc));
        }

        // Check if the cc value is null or an empty value
        if ((cc != null) && (cc != string.Empty))
        {
            // Set the CC address of the mail message
            mMailMessage.CC.Add(new MailAddress(cc));
        }

        // Set the subject of the mail message
        mMailMessage.Subject = subject;
        // Set the body of the mail message
        mMailMessage.Body = body;

        // Secify the format of the body as HTML
        mMailMessage.IsBodyHtml = true;
        // Set the priority of the mail message to normal
        mMailMessage.Priority = MailPriority.Normal;

        // Instantiate a new instance of SmtpClient
        SmtpClient mSmtpClient = new SmtpClient();
        // Send the mail message
        mSmtpClient.Send(mMailMessage);
        return true;
    }
   
}

create Default.aspx

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
            <asp:View ID="View1" runat="server">
                <table style="width: 308px">
                    <tr>
                        <td>
                            To:</td>
                        <td>
                            <asp:TextBox ID="txt_To" runat="server"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td>
                            Your Email:</td>
                        <td>
                            <asp:TextBox ID="txt_From" runat="server"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td>
                            CC:</td>
                        <td>
                            <asp:TextBox ID="txt_CC" runat="server"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td>
                            Subject:</td>
                        <td>
                            <asp:TextBox ID="txt_Subject" runat="server"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td>
                            Message:</td>
                        <td>
                            <asp:TextBox ID="txt_Message" runat="server" TextMode="MultiLine"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td>
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td>
                        </td>
                        <td style="text-align: right">
                            <asp:Button ID="Button1" runat="server" Font-Bold="True" OnClick="Button1_Click"
                                Text="Send" /></td>
                    </tr>
                </table>
            </asp:View>
            <asp:View ID="View2" runat="server">
                <br />
                Thank You
                <br />
                <br />
                Your Email has been sent<br />
                <br />
            </asp:View>
            <asp:View ID="View3" runat="server">
                <br />
                An Error accured during sending email<br />
                <br />
                click
                <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">here</asp:LinkButton>
                to try again.<br />
            </asp:View>
        </asp:MultiView></div>
    </form>
</body>
</html>

 

and in code behind:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Attributes.Add("onclick","document.body.style.cursor = 'wait'; this.value='Please wait...'; this.disabled = true; " + this.GetPostBackEventReference(Button1, string.Empty) + ";");

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        bool x = MailHelper.SendMailMessage(txt_From.Text, txt_To.Text, "", txt_CC.Text, txt_Subject.Text, txt_Message.Text);
        if (x == true)
        {
            MultiView1.ActiveViewIndex = 1;
        }
        else
        {
            MultiView1.ActiveViewIndex = 2;
        }
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 0;
    }
}

 

and in web.config

<configuration>
  <system.net>
    <mailSettings>
      <smtp from="your email">
        <network host="your smtp" port="25" userName="your email" password="xxxxxx"/>
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
 Good Luck
0
yasserzaid
7/11/2008 2:17:04 PM
Reply:

Similar Artilces:

Why do Sending SMTP Authenticated E-mail succeed using SmtpMail.Send() function but fail using SmtpClient.send() function ? Bugs in System.Net.Mail.SmtpClient when send a Authenticated E-mail?
I click btnOK button, the email can send OK, but click btnFail button,  the following error is displayed! why ? you can test the section code. The SMTP, username, password are valid!  Many thanks! "Syntax error, command unrecognized. The server response was: authentication failed,decode user password error" I have tested some other SMTP, somes is OK. I think there are some bugs with System.Net.Mail.SmtpClient when send a Authenticated E-mail with some SMTP!   //------------------------------------------.ASPX Code----------------------------------------...

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Sending Email using HTML file as Emailbody using Net.Mail.MailMessage... Please help
Hi all I can send emails with text or html emailbody using asp.net, but cannot find any method or example so far on the web to show how to use an html file as an emailbody. I have tried everything. I know how to do it with the old asp. I have created a html document for example newsletter.html. I want this document to be in the email body when the client opens the email. It must not load from another url. I suppose what i want to do is embed it into the email.Any help or examples will be appreciated as this is quite urgent for me to implement it for my client.  This is the code im ...

Sending email using System.net.Mail
 I am trying to send email using Asp .Net. I am using System.Net.Mail namespace. The code i written is below MailMessage message = new MailMessage(); message.From = new MailAddress("myemail@domain.com"); message.To.Add(new MailAddress("someone@domain.com")); message.Subject = "Test"; message.Body = "This is a test message"; message.IsBodyHtml = false; SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587); mailClient.Credentials = ne...

HOW TO: Send email using System.Net.Mail
Below is a C# and VB.NET class that demonstrates using System.Net.Mail to send an email. Download C# System.Net.Mail HelperDownload VB.NET System.Net.Mail Helper Calling the function from code MailHelper.SendMailMessage("fromAddress@yourdomain.com", "toAddress@yourdomain.com", "bccAddress@yourdomain.com", "ccAddress@yourdomain.com", "Sample Subject", "Sample body of text for mail message") MailHelper.cs using System.Net.Mail; public class MailHelper{   /// <summary>   /// Sends an mail ...

Send email using System.Net.Mail
hi to all,  while i am sending mail to gmail ,i am facing problem.but i can send mail to other smtp adress like(smtp.horasoft.in)plz give advice how to send email to gmail(i didn't give any details other than  below code).thank you in advance.   protected void btnSubmit_Click(object sender, EventArgs e)        {                                     &nbs...

HOW TO: Send email using System.Net.Mail
 Looks like they locked the thread in the FAQ section, so I'll just ask my question here. I"m using a version of the System.Net.Mail class that was posted in the FAQ section. I'm trying to use it like this:            string from = EmailTextBox.Text;            string to = ContactIdentifier.EmailAddress;            string bcc = "";            strin...

Sending Mail Using System.Net.Mail with out using User credentials
HI, I have an application where in i send mails based on some condition, the user is already authenticated, so i need not check the User Credentials.Right now this is how the piece lokks:- mailClient.Credentials = new NetworkCredential(USERID, USER_PWD,DOMAIN); I want to send the mail, with out validating the user credentials, Can i skip the above line. Please post aqlong with the sample code.   Thanx in Advance. Anil Kumar.   I think you cannot skip. but store user credentials in session variables after login and then pass.If this post was useful to you, please mark it as...

Send Email from form using system.net.mail
Please see code behind below. This my message is being received by only with hard coded text of subject with no body.  How do I correct my syntax so that the information is passed from form fields to email message?  The form data is being inserted into the db and redirected to .aspx page.  Just need to get data from for fields to message.  -------------------------------------------- Imports System.Net.MailPartial Class apps_contactpage Inherits System.Web.UI.PageSub Send2Mail(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs) 'create the mail...

Sending Email through System.Net.Mail is generating errors "Failure Sending mail
hi Sending Email through System.Web.Mail is working fine but System.Net.Mail is generating errors "Failure Sending mail  i treid in all possible ways but did't  pls help in giving a solution thanks & Regards vittal Maybe you can show us some code and post the exact error mesg as well (by looking at the value in ex.tostring)?My HomePage - www.findingsteve.net"It is more blessed to give than to receive." Acts 20: 35 (NIV, Bible)Progress - "Never discourage anyone...who continually makes progress, no matter how slow." Plato System.Web.Ma...

Edit email body before sending mail using vb.net
Code to Edit email body before sending mail to end users.Email body should contain username, Attached doc's list and some text.Any one plz in VB.net Thank you How far have you got with doing this yourself?  Are you getting error messages that you don't understand?  Have you developed the form to accept the initial text prior to allowing it to be edited?  If you have, all you need to do is display it in an editable format. Regards Mike [MVP - ASP/ASP.NET]My site You can try to create a email template for modifing when you send the email. hence you can replace ...

Sending Email with Net.Mail (No Email, no error)
hi,i'm using the system.net.Mail namespace to send an email from my application. when i send, the application does not fire any exception, neither does it send the email to my account.below is the code i'm using  Dim mmailMessage As New Net.Mail.MailMessage Dim mFrom As New Net.Mail.MailAddress(mailFrom) mmailMessage.From = mFrom Dim ll As String = "myname@ourmail.com" mmailMessage.To.Add(ll) mmailMessage.Subject = "Talk Concerns" mmailMessage.Body = "Testing Concerns One Two" Dim ...

get mail using System.Net.Mail
How can i get Email usign System.Net.Mail ?? Hello poloxy  ,the System.Net.Mail used only for sending emails and not to receive them.Read the full documentation at  MSDN Library http://technet.microsoft.com/en-us/library/system.net.mail.aspx  Hosam Kamel Remember to click on Mark as answer on the post that helped you SO how can I receive mail ? Try one of these pop3 librarieshttp://www.codeproject.com/info/search.aspx?artkw=pop3  Hosam Kamel Remember to click on Mark as answer on the post that helped you HI,   if you want to send email by using System....

Sending mails with Net.Mail: no Email, No Error
hi,i'm using the system.net.Mail namespace to send an email from my application. when i send, the application does not fire any exception, neither does it send the email to my account.below is the code i'm using  Dim mmailMessage As New Net.Mail.MailMessage Dim mFrom As New Net.Mail.MailAddress(mailFrom) mmailMessage.From = mFrom Dim ll As String = "myname@ourmail.com" mmailMessage.To.Add(ll) mmailMessage.Subject = "Talk Concerns" mmailMessage.Body = "Testing Concerns One Two" Dim sm As...

Web resources about - Sending Email using net.mail - asp.net.getting-started

Sending/receiving relationship - Wikipedia, the free encyclopedia
A sending/receiving relationship is one in which a public school district sends some or all of its students to attend the schools of another ...

U.K. Woman Faces 20 Months For Creating Fake Facebook Accounts, Sending Herself Abusive Messages
A woman in Cornwall in the U.K. came up with a creative way to use Facebook to accelerate a family spat, and it earned her 20 months in prison. ...

CHVRCHES - Dear guys, Please stop sending us emails like... - Facebook
Dear guys, Please stop sending us emails like this. This is one of the more polite ones. Other recent classics include "I'm going to give her ...

Facebook Sending Perez Hilton More Traffic than Google, Driving 3.3% of All US Traffic to Video Sites ...
For media companies evaluating their Facebook marketing strategy , here’s an interesting sign of the times: web analytics firm Hitwise is reporting ...

A better experience for sending Tweets and DMs - Twitter Blog
... panel New Tweet panel in da...... Skip to main content Blog Got an account? Sign in Search form Search &nbsp A better experience for sending ...

How to Go From Working 60 Hours a Week to 40 By Sending 2 Emails a Week
I’m convinced 95% of cubicle workers who work over 60 hours a week constantly can cut it down to 40-45 hours by sending 2 emails a week to their ...

Live Emoji - sending GIF Animation Emoji for Zoosk,Skype,Kik,Whatsapp,Facebook Messenger Etc. on the ...
Get Live Emoji - sending GIF Animation Emoji for Zoosk,Skype,Kik,Whatsapp,Facebook Messenger Etc. on the App Store. See screenshots and ratings, ...


Cynthia McKinney - responds to Obama on sending troops into Afghanistan - Debate Answer - YouTube
Cynthia McKinney, Green Party Presidential candidate, responds to Barack Obama on his support for sending troops into Afghanistan. Based on his ...

Great-grandmother 'would die' before sending kids to Italy
Great-grandmother 'would die' before sending kids to Italy

Resources last updated: 12/19/2015 7:46:51 PM