sendgrid / sendgrid-csharp

The Official Twilio SendGrid C#, .NetStandard, .NetCore API Library
https://sendgrid.com
MIT License
1.08k stars 584 forks source link

BCC not working #97

Closed craig-acutest closed 9 years ago

craig-acutest commented 9 years ago

Here is code I'm using to add a Blind carbon copy:

mail.AddBcc(staff.Email);

Where staff is an object with attributes about the staff member, one of which is email, this being a string containing the staff members email address.

We have recently moved our websites to Microsoft Azure, and investigated this as being the best solution to send emails.

We rely on sending BCC as this allows many people to get the email our customers get, so that internal company audits can be performed, it is important that the customer not see who is dealing with or who has receive the email.

Please can you show me why this isn't working? or if this is a bug i have found, can it be fixed?

Thanks,

Craig.

Full code of function below:

            public void emailQuote(string REFID, int ID)
                    {
        try
        {
            var refno = REFID.ToString().Split('-');

            var refid = refno[2];
            var custid = refno[1];
            var quoteid = refno[0];

            var quote = returnQuote(refid, Convert.ToInt32(custid));

            var customer = returnCustomer(quote.CustomerID);

            var ASMName = "";

            var mail = new SendGridMessage();
            string EmailTo = "";

            EmailTo = customer.Email;               

            string directEmailSubject = "Acutest Direct - New Quotation";

            mail.From = new MailAddress(Process.Constants.AcutestDirectEmail);

            if (quote.ASMID == 0)
            {
                mail.AddBcc(Process.Constants.AcutestDirectEmail);
            }
            else
            {
                var staff = AcutestLoginReader.StaffAPI.GetStaffByID(quote.ASMID);

                if(staff != null){
                    ASMName = staff.FirstName + " " + staff.Surname;
                    mail.AddBcc(staff.Email);
                }

                mail.AddBcc(Process.Constants.AcutestDirectEmail);
                mail.AddBcc(Process.Constants.AcutestAdmin);
            }
            mail.AddBcc(Process.Constants.AcutestWebTeam);
            mail.AddTo(EmailTo);
            mail.Subject = directEmailSubject;

            mail.AddAttachment(new MemoryStream(Utilities.Generator.CreatePDF(REFID, Process.Constants.WebsiteAddress, Process.Constants.WebsiteAddress + "/footerPDF.aspx")), "Quotation_" + refid + ".pdf");

            string emailBody = "<span>AcutestDirect is a Trading Division of Acute Sales Ltd<br/>" +
                                "Century Road<br/>" +
                                "High Carr Business Park<br/>" +
                                "Newcastle-under-Lyme<br/>" +
                                "Staffordshire<br/>" +
                                "ST5 7UG<br/></span><br/><br/>";

            emailBody += "<span>The information contained in this electronic mail message is confidential. It is intended solely for the use of the individual " +
            "or entity to whom it is addressed and others authorised to receive it. If the reader of this message is not the intended recipient, " +
            "you are hereby notified that any use, copying, dissemination or disclosure of this information is strictly prohibited.</span><br/><br/>";

            mail.Html = "Hello " + customer.FirstName + " " + customer.Surname + ",<br/><br/>Please find attached your quotation.<br/><br/>" +
                "Kind Regards,<br/><br/>" + ASMName + "<br/>Area Sales Manager" + "<br/><br/>" + emailBody;

            var credentials = new NetworkCredential(Constants.SendGridUsr, Constants.SendGridPwd);

            var transportWeb = new Web(credentials);

            transportWeb.Deliver(mail);
        }
        catch (Exception err)
        {
            Elmah.ErrorSignal.FromCurrentContext().Raise(err);
            emailError("emailDeclineQuote", "Email:" + Process.Constants.AcutestDirectEmail + " Error:" + err.ToString());
        }
    }
0xdeafcafe commented 9 years ago

outdated

brandonmwest commented 9 years ago

@0xdeafcafe BCC was put back in in 5.0.0 and the web api supports it now https://github.com/sendgrid/sendgrid-csharp/blob/master/SendGrid/SendGridMail/SendGrid.cs#L188-L197

Not sure what's going on here

0xdeafcafe commented 9 years ago

@brandonmwest oops! removed my comment.

@craig-acutest could you set up fiddler and inspect the request going out?

craig-acutest commented 9 years ago

@0xdeafcafe I will do now...

Is there anything in particular I'm looking for?

thanks

Here is output:

HTTP/1.1 200 Connection Established FiddlerGateway: Direct StartTime: 18:38:03.204 Connection: close EndTime: 18:39:10.161 ClientToServerBytes: 249659 ServerToClientBytes: 5470

This is a CONNECT tunnel, through which encrypted HTTPS traffic flows. To view the encrypted sessions inside this tunnel, enable the Tools > Fiddler Options > HTTPS > Decrypt HTTPS traffic option.

A SSLv3-compatible ServerHello handshake was found. Fiddler extracted the parameters below.

Version: 3.1 (TLS/1.0) SessionID: empty Random: 54 AE CE 8B 86 FA 19 F3 A4 14 16 07 E8 C4 41 07 E0 15 C0 EB 14 A2 BE B0 0F 87 10 7A DC 18 CE 11 Cipher: TLS_RSA_AES_128_SHA [0x002F] CompressionSuite: NO_COMPRESSION [0x00] Extensions: renegotiation_info 00 SessionTicket empty

0xdeafcafe commented 9 years ago

You'll have to add the fiddler https cert to your system, and allow it to sniff HTTPS packets. The instructions on doing so are listed in that output.

When you've done that, you'll be able to see the POST payload, and the headers of the request.

craig-acutest commented 9 years ago

Here is decrypted output, with API details HIDDEN:

--5d906b49-b109-4796-b3d8-956d0818e9da Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=api_user

HIDDEN --5d906b49-b109-4796-b3d8-956d0818e9da Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=api_key

HIDDEN --5d906b49-b109-4796-b3d8-956d0818e9da Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=from

sales@acutesales.co.uk --5d906b49-b109-4796-b3d8-956d0818e9da Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=subject

Acutest Direct - New Quotation --5d906b49-b109-4796-b3d8-956d0818e9da Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=html

Hello Craig Williams,

Please find attached your quotation.

To view datasheets regarding products quoted for please use the links below:

PROMO MACROTOUCH Multifunction Tester - Introductory Price


Data Sheet_5552.pdf

Brochure_5552.pdf

Catalogue_5552.pdf

Professional Electrician Published Article_5552.pdf

Kind Regards,

Richard Guthrie
Area Sales Manager

AcutestDirect is a Trading Division of Acute Sales Ltd
Century Road
High Carr Business Park
Newcastle-under-Lyme
Staffordshire
ST5 7UG


The information contained in this electronic mail message is confidential. It is intended solely for the use of the individual or entity to whom it is addressed and others authorised to receive it. If the reader of this message is not the intended recipient, you are hereby notified that any use, copying, dissemination or disclosure of this information is strictly prohibited.

--5d906b49-b109-4796-b3d8-956d0818e9da Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name="to[]"

generalcaw@gmail.com --5d906b49-b109-4796-b3d8-956d0818e9da Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name="bcc[]"

richard.guthrie@acutesales.co.uk --5d906b49-b109-4796-b3d8-956d0818e9da Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name="bcc[]"

sales@acutesales.co.uk --5d906b49-b109-4796-b3d8-956d0818e9da Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name="bcc[]"

craig.williams@acutesales.co.uk --5d906b49-b109-4796-b3d8-956d0818e9da Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name="bcc[]"

web@acutesales.co.uk --5d906b49-b109-4796-b3d8-956d0818e9da Content-Disposition: form-data; name="files[Quotation_08011526RG.pdf]"; filename=Quotation_08011526RG.pdf Content-Type: application/octet-stream

%PDF-1.4 %
1 0 obj << /Pages 2 0 R /Outlines 3 0 R /PageLayout /OneColumn /Type /Catalog /OutputIntents [<< /OutputCondition () /OutputConditionIdentifier (Custom) /RegistryName () /Info (sRGB IEC61966-2.1) /Type /OutputIntent /DestOutputProfile 4 0 R /S /GTS_PDFA1

] /ViewerPreferences 5 0 R /PageMode /UseNone

endobj 2 0 obj << /Count 1 /Kids [6 0 R] /Type /Pages

endobj 6 0 obj << /Resources << /ProcSet [/PDF /Text /ImageC] /XObject << /EvoPdf_ggkohaidjdjjkhanolabafcplngdmagl 7 0 R /EvoPdf_flpcjlplcpdmkichoihckefffiifajac 8 0 R /EvoPdf_laddmnbpokikkpfkpibbophkmjpjdnnc 9 0 R

/Parent 2 0 R /MediaBox [0.00000 0.00000 595.00000 842.00000] /Annots [10 0 R] /Type /Page /Contents [11 0 R 12 0 R]

endobj 11 0 obj << /Filter /FlateDecode /Length 136

stream x^M ; 0D{K Þ lB=T ljH a#o  N  |m 3H[ k D    " H 7  ~ U .`+JTK V  N~ >nއ r (ϔ R SX c 8;s e0 endstream

endobj 12 0 obj << /Filter /FlateDecode /Length 151

stream x^ ; 0D{K Þ

0xdeafcafe commented 9 years ago

That's very strange. It looks like the post body is fine. Next thing I can suggest is going to https://sendgrid.com/logs/index and seeing if the to and bcc emails are being shown there.

nb: you might want to modify that comment as it has links to pdf documents that might be private. as well as the customers email address.

craig-acutest commented 9 years ago

Hi @0xdeafcafe, Thanks for your help so far, it looks like my bcc emails are bouncing:

email: craig.williams@acutesales.co.uk

type: bounce

reason: 554 5.7.1 Command rejected

smtp-id: 14acb2d0f10.34bf.3abd6a@ismtpd-033

processed string: January 8, 2015 - 08:12:23 PM

is this something for sendgrid support, or could the command being sent through from the API be incorrect somewhere?

Thanks.

0xdeafcafe commented 9 years ago

If you open a ticket here https://support.sendgrid.com/hc/en-us/requests/new detailing the bounce, the SendGrid support team will look into it. Anything else you could suggest @brandonmwest?

craig-acutest commented 9 years ago

Thank you so much @0xdeafcafe you've been a great help. I will raise a ticket and keep you informed.

craig-acutest commented 9 years ago

Hi guys,

It looks like there is a spam filter that the IT Support People here didn't know existed, and has been blocking Emails sent from sendgrid.

Its what i'm up against everyday with my job here, spending hours and being told its not our fault only to prove its there fault. In my opinion, they should have an audit log on all systems and changes to those systems. Similar to how GIT handles my code changes, and what i put in place on the admin side of my websites to track who changes what.

Thank you guys a lot especially @0xdeafcafe.

brandonmwest commented 9 years ago

@craig-acutest Glad you got it sorted out! Thanks @0xdeafcafe

0xdeafcafe commented 9 years ago

Anytime @craig-acutest! Glad you got it sorted 💃