Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
2.6 kB
1
Indexable
Never
 static string  endpoint = "https://commsrvcommunicationservices.india.communication.azure.com/";
        string accessKey = "InwmLbfmq9uRdPprvcPdVgu8HcWLEAqwZEr+8llN909PdVSi8WAwaYqRLNCihzn9j0n80deAha33pEg6XPGBCw==";
        private void button1_Click(object sender, EventArgs e)
        {
            
            bool status = false;

            OpenFileDialog OpenFile = new OpenFileDialog();
            OpenFile.InitialDirectory = @"c:\";
            //OpenFile.Filter = "ZIP Folders(*.ZIP; *.7z)| *.zip; *.7z";
            OpenFile.FilterIndex = 2;
            OpenFile.RestoreDirectory = true;
            if (OpenFile.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = OpenFile.FileName;
            }
            string connectionString = /*Environment.GetEnvironmentVariable(*/"endpoint=https://commsrvcommunicationservices.india.communication.azure.com/;accesskey=InwmLbfmq9uRdPprvcPdVgu8HcWLEAqwZEr+8llN909PdVSi8WAwaYqRLNCihzn9j0n80deAha33pEg6XPGBCw=="/*)*/;
            EmailClient emailClient = new EmailClient(connectionString);
            var emailContent = new EmailContent("Welcome to Azure Communication Service Email APIs.")
            {
                PlainText = "This email message is sent from Azure Communication Service Email.",
                Html = "<html><body><h1>Quick send email test</h1><br/><h4>This email message is sent from Azure Communication Service Email.</h4><p>This mail was sent using .NET SDK!!</p></body></html>"
            };

            // Create the EmailMessage
            var emailMessage = new EmailMessage(
                senderAddress: "DoNotReply@c2bedda9-8b73-4eb0-b795-535accaed4fd.azurecomm.net",

        recipientAddress: "sonamshinde0807@gmail.com",
            
                content: emailContent);
            
           
            // Create the EmailAttachment
            var filePath = textBox1.Text;
            byte[] bytes = File.ReadAllBytes(filePath);
            var contentBinaryData = new BinaryData(bytes);
            var emailAttachment = new EmailAttachment("attachment.pdf", MediaTypeNames.Application.Pdf, contentBinaryData);

            emailMessage.Attachments.Add(emailAttachment);

            try
            {
                EmailSendOperation emailSendOperation = emailClient.Send(WaitUntil.Completed, emailMessage);
                EmailSendResult statusMonitor = emailSendOperation.Value;
                if (statusMonitor.Status == "Succeeded")
                    status = true;
                label1.Text = status.ToString();
            }
Leave a Comment