Sending meeting request to more than one email using c# code - c#

i wrote a function using c# , that is sending a meeting request to an email address .
i want to modify this function just to be able to send the meeting request to more to more than one Recipients .
where should i set the code that is responsible for this , down here is my code that implements this
string startTime1 = Convert.ToDateTime(startTime).ToString("yyyyMMddTHHmmssZ");
string endTime1 = Convert.ToDateTime(endTime).ToString("yyyyMMddTHHmmssZ");
MailMessage msg = new MailMessage(mailfrom, emailto);
msg.Subject = Subject;
msg.Body = emailbody;
#region Calender Request
StringBuilder str = new StringBuilder();
str.AppendLine("BEGIN:VCALENDAR");
//PRODID: identifier for the product that created the Calendar object
str.AppendLine("PRODID:-//test //Outlook MIMEDIR//EN");
str.AppendLine("VERSION:2.0");
str.AppendLine("METHOD:REQUEST");
str.AppendLine("BEGIN:VEVENT");
str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", startTime1));//TimeZoneInfo.ConvertTimeToUtc("BeginTime").ToString("yyyyMMddTHHmmssZ")));
str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", endTime1));//TimeZoneInfo.ConvertTimeToUtc("EndTime").ToString("yyyyMMddTHHmmssZ")));
str.AppendLine(string.Format("LOCATION: {0}", "Location"));
// UID should be unique.
str.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
str.AppendLine(string.Format("DESCRIPTION:{0}", msg.Body));
str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", msg.Body));
str.AppendLine(string.Format("SUMMARY:{0}", msg.Subject));
str.AppendLine("STATUS:CONFIRMED");
str.AppendLine("BEGIN:VALARM");
str.AppendLine("TRIGGER:-PT15M");
str.AppendLine("ACTION:Accept");
str.AppendLine("DESCRIPTION:Reminder");
str.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:BUSY");
str.AppendLine("END:VALARM");
str.AppendLine("END:VEVENT");
str.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", msg.From.Address));
str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", msg.To[0].DisplayName, msg.To[0].Address));
str.AppendLine("END:VCALENDAR");
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
ct.Parameters.Add("method", "REQUEST");
ct.Parameters.Add("name", "meeting.ics");
AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct);
msg.AlternateViews.Add(avCal);
#endregion
SmtpClient client = new SmtpClient("smtp.outlook.com", 587);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("lma#test.com", "test1234");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Send(msg);

You can send many more with BCC or CC property
MailAddress bcc = new MailAddress("manager1#contoso.com");
msg.Bcc.Add(bcc);
The above two lines of code will just send the appointment(.ics) items, but it won't give the rsvp response back to the organizer. Also it will hide the Response options!!!
So you need to have the attendees set as like below code :
str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", msg.To[0].DisplayName, "manager1#contoso.com")); //Attendee 1
str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", msg.To[0].DisplayName, "manager2#contoso.com")); // Attendee 2

Use BCC or CC property
MailAddress bcc = new MailAddress("manager1#contoso.com");
msg.Bcc.Add(bcc);
You can add as many Recipients as you want
Bcc
Cc

Related

Send multiple emails from listbox c#

hi im geting my email list from db in a listbox(email_c) and i need to send to all
this is the error that i get with my code
System.FormatException: 'The specified string is not in the form required for an e-mail address.'
login = new NetworkCredential(txtuser.Text, txtPassword.Text);
client1 = new SmtpClient(txtSmtp.Text);
client1.Port = Convert.ToInt32(txtPort.Text);
client1.Credentials = login;
string emails = email_c.GetItemText(email_c.Items);
msg = new MailMessage { From = new MailAddress(txtuser.Text + txtSmtp.Text.Replace("smtp.", "#"), "Sesizare", Encoding.UTF8) };
msg.To.Add(new MailAddress(emails));
if (!string.IsNullOrEmpty(txtCC.Text))
msg.To.Add(new MailAddress(txtCC.Text));
msg.Subject = txtSubject.Text;
msg.Body = "Abonamentul dumneavoastra a fost activat";
msg.BodyEncoding = Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.Normal;
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client1.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
string userstate = "Ttimite...";
client1.SendAsync(msg, userstate);
The MailAddress does represent the address of an electronic mail sender or recipient. That means it is one single email.
Because of that, instead of writing all the email string into a single string variable you should iterate over the items in the listbox and add each of them individually to the MailMessage. Something like this:
foreach (var email in email_c.Items)
{
msg.To.Add(new MailAddress(email.ToString()));
}

I want to email the screenshot in tabular format stored in my local using C#?

I want to automate my work by sending the screenshot taken during automation in tabular email format . I had successfully attached as document, but I want it in tabular format. This is code what I had already tried
public static void email_send() {
string htmlBody = "<html><body><h1>Picture</h1><br><img src=\"cid:test1.jpeg\"></body></html>";
AlternateView avHtml = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
LinkedResource inline = new LinkedResource("test1.jpeg", MediaTypeNames.Image.Jpeg);
inline.ContentId = Guid.NewGuid().ToString();
avHtml.LinkedResources.Add(inline);
Attachment att = new Attachment(#"D:/test123.png");
att.ContentDisposition.Inline = true;
MailMessage mail = new MailMessage();
mail.AlternateViews.Add(avHtml);
System.Net.Mail.SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("*****");
mail.To.Add("*******");
mail.Subject = "Test Mail - 1";
mail.Body = String.Format(
"<h3>Client: " + " Has Sent You A Screenshot</h3>" +
#"<img src=""cid:{0}"" />", inline.ContentId);
mail.IsBodyHtml = true;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("******", "******");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
You have missed the attachment.
Your linked resource also needs to be attached to the email. You need to add the following code:
mail.Attachments.Add(att);

CDO not sending internal mails

I am using CDO from sending emails.
It is the only way I found that works from a certian customer. Standard smtp sending does not
the problem with this method is that it works ok for external email recipients but not for the internal ones.
CDO.Message oMsg = new CDO.Message();
CDO.IConfiguration iConfg;
iConfg = oMsg.Configuration;
ADODB.Fields oFields;
oFields = iConfg.Fields;
ADODB.Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
oField.Value = 2;
ADODB.Field oServer = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
oServer.Value = Server;
oFields.Update();
oMsg.Subject = subject;
oMsg.From = Sender;
oMsg.To = recipient;
oMsg.HTMLBody = body;
oMsg.Send();
Hope someone has an idea
The code does not break
it just does not send an emal.
Can I get an error from the object somehow?

sending email in asp.net sends password instead of email

I am trying to send email after user has been registered successfully. but it sends password in FROM section instead of sending email like abc#gmail.com here it sends 1234kjfh. what am I missing here?
string name=txtfirstname.Text;
string fileName = Server.MapPath("~/App_Data/TextFile.txt");
string mailBody = File.ReadAllText(fileName);
mailBody = mailBody.Replace("##Name##", txtfirstname.Text);
mailBody = mailBody.Replace("##Email##", email);
mailBody = mailBody.Replace("##Phone##", txtphone.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Re: Activate your account for AIS FORUM";
myMessage.Body = mailBody;
myMessage.From = new MailAddress("abc#gmail.com", "1234kjfh");
myMessage.To.Add(new MailAddress(txtemail.Text, email));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.EnableSsl = true;
mySmtpClient.Send(myMessage);
Plz help!
The second parameter of the constructor of MailAddress is displayName. You aren't setting the credentials used to send the mail, you are setting the display name.
To set the credentials, use SmtpClient.Credentials:
SmtpClient client = new SmtpClient(server, port);
client.Credentials = new NetworkCredential("username", "password");
You missing something here
new MailAddress(address, displayName)
so, you have added display name as "1234kjfh"
Update your code as follow.
string name=txtfirstname.Text;
string fileName = Server.MapPath("~/App_Data/TextFile.txt");
string mailBody = File.ReadAllText(fileName);
mailBody = mailBody.Replace("##Name##", txtfirstname.Text);
mailBody = mailBody.Replace("##Email##", email);
mailBody = mailBody.Replace("##Phone##", txtphone.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Re: Activate your account for AIS FORUM";
myMessage.Body = mailBody;
myMessage.From = new MailAddress("abc#gmail.com", "abc#gmail.com");
myMessage.To.Add(new MailAddress(txtemail.Text, email));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.EnableSsl = true;
mySmtpClient.Send(myMessage);
Hope this helps.

Sending meeting request with file attachment C#

I need to send a metting request for Outlook 2013 with a file attachment in C#.
I have already working code to send a request but i really have no idea how to add an attachment to this.
MailMessage message = new MailMessage();
message.To.Add("someMail");
message.Subject = "Test";
message.From = new MailAddress("myMail");
message.Body = "Test Test";
SmtpClient smtp = new SmtpClient("mySmtp");
StringBuilder str = new StringBuilder();
str.AppendLine("BEGIN:VCALENDAR");
str.AppendLine("VERSION:2.0");
str.AppendLine("METHOD:REQUEST");
str.AppendLine("BEGIN:VEVENT");
str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmZ}", DateTime.UtcNow));
str.AppendLine(string.Format("DTSTART:{0}", startTime));
str.AppendLine(string.Format("DTEND:{0}", endTime));
str.AppendLine("LOCATION: Zürich");
str.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
str.AppendLine(string.Format("DESCRIPTION:{0}", message.Body));
str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", message.Body));
str.AppendLine(string.Format("SUMMARY:{0}", message.Subject));
str.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", message.From.Address));
str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", message.To[0].DisplayName, message.To[0].Address));
str.AppendLine("BEGIN:VALARM");
str.AppendLine("TRIGGER:-PT15M");
str.AppendLine("ACTION:DISPLAY");
str.AppendLine("DESCRIPTION:Reminder");
str.AppendLine("END:VALARM");
str.AppendLine("END:VEVENT");
str.AppendLine("END:VCALENDAR");
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
ct.Parameters.Add("method", "REQUEST");
AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct);
message.AlternateViews.Add(avCal);
smtp.Send(message);
I hope someone can help
Thanks Ego
You can try Below code
MailMessage msg = new MailMessage();
byte[] byteArray = Encoding.UTF8.GetBytes(str.ToString());
Stream contentStream = new MemoryStream(byteArray);
Attachment attachment = new Attachment(contentStream, "calendar.ics", "text/calendar");
attachment.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
msg.Attachments.Add(attachment);

Categories

Resources