how to send e-mail to list of recipients e-mail addresses instead of store owner/admin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
i am using this as reference :

https://www.nopcommerce.com/boards/t/3177/urgent-i-need-to-create-a-new-page-with-a-fill-in-form-how-.aspx?p=3
13 years ago
The code I gave you is better than the code you were given in that thread.

However that thread has sent you on a wild goose chase because from what I can see you can't add an attachment and then send it via NopCommerce. There aren't any suitable method overloads in MailManager that I can find. You'll need to create a SmtpClient object yourself. Let me know if you don't know how to do that and I'll knock something up.
13 years ago
yes Stephen i would really appreciate if you could help me with the code for this issue...
13 years ago
I've tested this with my own email addresses and received the message and attachment.

Put this in the Careers class:
protected static readonly MailAddress from = new MailAddress(MessageManager.AdminEmailAddress, MessageManager.AdminEmailDisplayName);
        protected static readonly List<MailAddress> to = new List<MailAddress> { new MailAddress("[email protected]"), new MailAddress("[email protected]"), new MailAddress("[email protected]") };

Your new try block:

                try
                {
                    //'(1) Create the MailMessage instance
                    MailMessage mm = new MailMessage { From = from };
                    foreach (var recipient in to)
                    {
                        mm.To.Add(recipient);
                    }

                    //'(2) Assign the MailMessage's properties
                    mm.Subject = "Message Careers";
                    mm.Body = Body.Text;
                    mm.IsBodyHtml = false;

                    //'Attach the file
                    mm.Attachments.Add(new Attachment(AttachmentFile.PostedFile.InputStream, AttachmentFile.FileName));

                    // Copied from Nop:
                    var smtpClient = new SmtpClient();
                    smtpClient.UseDefaultCredentials = MessageManager.AdminEmailUseDefaultCredentials;
                    smtpClient.Host = MessageManager.AdminEmailHost;
                    smtpClient.Port = MessageManager.AdminEmailPort;
                    smtpClient.EnableSsl = MessageManager.AdminEmailEnableSsl;
                    if (MessageManager.AdminEmailUseDefaultCredentials)
                        smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
                    else
                        smtpClient.Credentials = new NetworkCredential(MessageManager.AdminEmailUser, MessageManager.AdminEmailPassword);
                    smtpClient.Send(mm);

                    //'Show the EmailSentForm Panel and hide the EmailForm Panel
                    LBLSuccErr.Visible = true;
                    LBLSuccErr.ForeColor = System.Drawing.Color.Green;
                    LBLSuccErr.Text = "Your file has been submitted successfully";
                }
13 years ago
Hello Stephen ,
could you please post the complete code of your page so that i can understand exactly where to make the changes?

and if possible could you please advise me with this too ?
https://www.nopcommerce.com/boards/t/3177/urgent-i-need-to-create-a-new-page-with-a-fill-in-form-how-.aspx?p=3
13 years ago
I used the page you posted. Have deleted it now. Just replace your try block mine and put the other 2 lines at the start of the class.
13 years ago
Hello Stephen,

I used the code you provided me and it worked just like i wanted....Thanks a lot...

I have 2 questions regarding this code,

1)  when i fill out the information in the form, the information is sent to all the 3 e-mail addresses i mentioned in the code, but all 3 recipients of this information can see other recipient's name and address in the "TO " field of their mailbox.

Is it possible to hide other recipients and only show the e-mail address which will be specific to that recipient ?

The reason i pointed out this thing because for my other form i am using the code from here:
https://www.nopcommerce.com/boards/t/3177/urgent-i-need-to-create-a-new-page-with-a-fill-in-form-how-.aspx?p=3
and this code only shows the e-mail address of particular recipient only in "To" and doesn't show who else is getting the same information.

2) I added one more upload file tool which is option . so the website member who is filling the information in this form have to upload something in the first option and second option is optional , he/she may upload second file or leave it blank.

i added second upload feature in page
<asp:FileUpload ID="FileUpload1" runat="server" Height="28px" Width="248px" />


and added code in .cs file like this:

mm.Attachments.Add(new Attachment(AttachmentFile.PostedFile.InputStream, AttachmentFile.FileName));
mm.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));


Now  the problem is when i fill the complete form, i receive everything along with 2 files, but when i upload only 1 file in the required upload field and leave the second upload option i receive the  first file but i receive a NULL value file named as "ATT000001..bin" in place of the second upload option. How i can get rid of this bin file ?
13 years ago
Loop through the To collection and create a new message for each recipient, rather than loop through it to add each recipient to the same message.

With the input you probably need to check the length of the input stream and not attach if the length is 0.

These are very basic programming questions, probably better suited to somewhere like StackOverflow where people are eager to answer questions in order to collect points :)
13 years ago
i was able to solve my problem....
Thanks a lot stephen for your help and time.. really appreciate it !!!
13 years ago
Great!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.