locked
send email with to different message one message for "to"and other message for "cc" RRS feed

  • Question

  • Hi,

    I am sending email using webpart (below is my code working successfully).

    ---

        public void Mailmseesage(int flag, int userid, string usernamewhouploadedDoc, string docname, string mesgtype, string siteurl, string username)
            {
                string message = "";
                string sub = "";

                clsUser oUser = new clsUser();
                List<clsUser> lstuer = new List<clsUser>();
                lstuer = oUser.RetriveUserByID(userid, siteurl, 1);
                string emaildocumentupload = "";
                if (lstuer.Count > 0)
                {
                    emaildocumentupload = lstuer[0].EmailID;
                }
                try
                {

                    MailMessage theMsg = new MailMessage();
                     theMsg.From = new MailAddress("de@grp.com");
                    theMsg.To.Add(emaildocumentupload);
                    if (flag == 1)
                    {
                        message = "Hi \n \n Your Document <b>'" + docname.ToUpper() + "'</b> has been successfully uploaded in the system by <b>'" + lstuer[0].UserName.ToUpper() + "'</b> pending approval.<br> <br> <br>\n \n " + siteurl + "\n \n .<br> <br> Thanks.";
                        // message = "Hi, \n \n Document '" + docname + "' is uploaded By " + lstuer[0].UserName.ToUpper() + ". \n \n requiring your response. \n  \n Thanks.";
                        sub = "Document is uploaded By " + lstuer[0].UserName.ToUpper() + "using Dejavu. ";
                        //get supervisor and admin of same dept to email on upload document
                        lstuer = oUser.RetriveUsersupervisor(lstuer[0].DepartID, siteurl, 3, 1);
                        foreach (clsUser ouser in lstuer)
                        {
                            //  theMsg.To.Add(new MailAddress(ouser.EmailID));
                            theMsg.CC.Add(new MailAddress(ouser.EmailID));
                        }
                    }
                    else
                    {
                        message = "Hi \n \n <b>" + usernamewhouploadedDoc.ToUpper() + "</b>, " + " Your document <b> '" + docname.ToUpper() + "' </b> has been " + mesgtype + " by the department supervisor . \n \n  " + siteurl + "\n \n Thanks. \n" + username.ToUpper();
                        //                    message = "Hi, \n \n" + usernamewhouploadedDoc.ToUpper() + ", your document '" + docname + "' has been " + mesgtype + " by the department supervisor \n  \n Thanks. \n " + username.ToUpper();
                        sub = "Document '" + docname + "' is " + mesgtype + ".";
                        theMsg.To.Add(new MailAddress(lstuer[0].EmailID));

                    }
                    theMsg.Body = message;
                  
                    theMsg.Subject = sub;
                    theMsg.IsBodyHtml = true;
                     var smptClient = new SmtpClient("mail.grp.com")
                    {
                         Credentials = new NetworkCredential("dejavu@iblgrp.com", "ibl@1234"),
                        EnableSsl = false
                    };
                    smptClient.Send(theMsg);
                }
                catch (Exception ex)
                {
                   throw ex
                }

            }

    Problem:

    for "to " I want to type and send different message and for"cc" I want to type different message

    Like:

    messagebodyTo : "hi your  mail successfully send to supervisor "

    messagebodyCC: "Hi, Mr x. send to email needs ur approval thanks"

    Thanks

    Friday, May 3, 2019 11:52 AM

Answers

All replies

  • I'd try asking for help over here.

    https://forums.iis.net/

    https://forums.asp.net/

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    Friday, May 3, 2019 1:45 PM
  • Hello,

    your code looks like C# (e.g. the MailMessage class is C#).

    You could ask here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral

    By the way, if you want to send 2 emails, why don't you just copy the email and put another recipient in it?

    Regards, Guido

    Monday, May 6, 2019 6:01 AM
  • in 1 go , can we do this?
    Tuesday, May 7, 2019 6:27 AM
  • This is "where is" forum for direction on where best to ask questions, so better to ask in dedicated forums we linked.

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    Tuesday, May 7, 2019 1:45 PM
  • in 1 go , can we do this?
    No, you will have to send 2 different emails. Think about it, the purpose of CC and BCC is so that those recipients can see the message that was sent to the TO recipient. 

    • Edited by MotoX80 Tuesday, May 7, 2019 5:26 PM
    Tuesday, May 7, 2019 1:55 PM