smtp отправка

Регистрация
27.08.2018
Сообщения
39
Благодарностей
3
Баллы
8
Нашел на форуме отправку SMTP писем через C#,не могу понять как добавить сюда отправку сообщений скрытой копии,буду рад за помощь
Код:
// sender email
var fromEmailString = project.Variables["fromEmail"].Value;
// recipient
var toEmailString = project.Variables["toEmail"].Value;
// email login for authorization
var login = project.Variables["login"].Value;
// email password of the sender
var password = project.Variables["password"].Value;
// email server
var server = project.Variables["server"].Value;
// email port
int port;
int.TryParse(project.Variables["port"].Value, out port);
// enable SSL or not (for instance required for Gmail)
bool encryptConnection;
bool.TryParse(project.Variables["encryptedConnection"].Value, out encryptConnection);
// message
var messageText = project.Variables["messageBody"].Value;
// title
var messageSubject = project.Variables["messageSubject"].Value;
// attachment path, leave it empty in case you want to attach nothing
var fileToAttach = project.Variables["fileToAttach"].Value;

// format email headers
var fromAddress = new System.Net.Mail.MailAddress(fromEmailString, fromEmailString);
var toAddress = new System.Net.Mail.MailAddress(toEmailString, toEmailString);
// create connecting to the server
var smtp = new System.Net.Mail.SmtpClient {
                            Host = server,
                            Port = port,
                            EnableSsl = encryptConnection,
                            DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
                            UseDefaultCredentials = false,
                            Credentials = new System.Net.NetworkCredential(login, password)
                        };
// create a message
var message = new System.Net.Mail.MailMessage(fromAddress, toAddress) {
                                        Subject = messageSubject,
                                        Body = messageText,
                                        IsBodyHtml = false,
                                    };
// if there is attachment we add it
if (!string.IsNullOrEmpty(fileToAttach))
{
    var attach = new System.Net.Mail.Attachment(fileToAttach);
    message.Attachments.Add(attach);
}
smtp.Send(message);
message.Dispose();
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)