Решение:
Пример с объяснениями
protected void Button1_Click(object sender, EventArgs e) { // SendMailMessage("fromAddress@yourdomain.com", "toAddress@yourdomain.com", "bccAddress@yourdomain.com", // "ccAddress@yourdomain.com", "Sample Subject", "Sample body of text for mail message"); SendMailMessage("seminar222@rudensoft.ru", "hecrus@mail.ru", "", "hecruss@gmail.com", "Привет с Infobox", "Это тело письма"); Response.Write("Success"); }
1. SendMailMessage – функция та же
2. В поле from надо указывать любой ящик, но в этого же домена, например xyz@rudensoft.ru(домен как в параметре smtp from)
Настройки веб-конфиг:
<system.net> <mailSettings> <smtp from="seminar@rudensoft.ru" deliveryMethod="Network"> <network host="mail.infobox.ru" password="xxxxx" port="25" userName="seminar@rudensoft.ru" /> </smtp> </mailSettings> </system.net>
Вызов функции:
MailHelper.SendMailMessage("fromAddress@yourdomain.com", "toAddress@yourdomain.com", "bccAddress@yourdomain.com", "ccAddress@yourdomain.com", "Sample Subject", "Sample body of text for mail message")
{ /// <summary> /// Sends an mail message /// </summary> /// <param name="from">Sender address</param> /// <param name="to">Recepient address</param> /// <param name="bcc">Bcc recepient</param> /// <param name="cc">Cc recepient</param> /// <param name="subject">Subject of mail message</param> /// <param name="body">Body of mail message</param> MailHelper.cs using System.Net.Mail; public class MailHelper public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body) { // Instantiate a new instance of MailMessage MailMessage mMailMessage = new MailMessage(); // Set the sender address of the mail message mMailMessage.From = new MailAddress(from); // Set the recepient address of the mail message mMailMessage.To.Add(new MailAddress(to)); // Check if the bcc value is null or an empty string if ((bcc != null) && (bcc != string.Empty)) { // Set the Bcc address of the mail message mMailMessage.Bcc.Add(new MailAddress(bcc)); } // Check if the cc value is null or an empty value if ((cc != null) && (cc != string.Empty)) { // Set the CC address of the mail message mMailMessage.CC.Add(new MailAddress(cc)); } // Set the subject of the mail message mMailMessage.Subject = subject; // Set the body of the mail message mMailMessage.Body = body; // Set the format of the mail message body as HTML mMailMessage.IsBodyHtml = true; // Set the priority of the mail message to normal mMailMessage.Priority = MailPriority.Normal; // Instantiate a new instance of SmtpClient SmtpClient mSmtpClient = new SmtpClient(); // Send the mail message mSmtpClient.Send(mMailMessage); } } MailHelper.vb Imports System.Net.Mail Public Class MailHelper <summary> Sends an mail message </summary> <param name="from">Sender address</param> <param name="recepient">Recepient address</param> <param name="bcc">Bcc recepient</param> <param name="cc">Cc recepient</param> <param name="subject">Subject of mail message</param> <param name="body">Body of mail message</param> Public Shared Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, ByVal subject As String, ByVal body As String) ' Instantiate a new instance of MailMessage Dim mMailMessage As New MailMessage() ' Set the sender address of the mail message mMailMessage.From = New MailAddress(from) ' Set the recepient address of the mail message mMailMessage.To.Add(New MailAddress(recepient)) ' Check if the bcc value is nothing or an empty string If Not bcc Is Nothing And bcc <> String.Empty Then ' Set the Bcc address of the mail message mMailMessage.Bcc.Add(New MailAddress(bcc)) End If ' Check if the cc value is nothing or an empty value If Not cc Is Nothing And cc <> String.Empty Then ' Set the CC address of the mail message mMailMessage.CC.Add(New MailAddress(cc)) End If ' Set the subject of the mail message mMailMessage.Subject = subject ' Set the body of the mail message mMailMessage.Body = body ' Set the format of the mail message body as HTML mMailMessage.IsBodyHtml = True ' Set the priority of the mail message to normal mMailMessage.Priority = MailPriority.Normal ' Instantiate a new instance of SmtpClient Dim mSmtpClient As New SmtpClient() ' Send the mail message mSmtpClient.Send(mMailMessage) End Sub End Class Web.config <?xml version="1.0"?> <configuration> <system.net> <mailSettings> <smtp from="defaultEmail@yourdomain.com"> <network host="smtp.yourdomain.com" port="25" userName="yourUserName" password="yourPassword"/> </smtp> </mailSettings> </system.net> </configuration>
https://falconspace.ru/blog/bazovye-voprosy-i-ponyatiya-v-sfere-sozdaniya-veb-proektov - Основы веб-разработки. Базовые понятия для владельца сайта
https://falconspace.ru/blog/bazovye-voprosy-i-ponyatiya-v-sfere-sozdaniya-veb-proektov - Основы веб-разработки. Базовые понятия для владельца сайта
https://falconspace.ru/blog/bazovye-voprosy-i-ponyatiya-v-sfere-sozdaniya-veb-proektov - Основы веб-разработки. Базовые понятия для владельца сайта
Поскольку коммуникация и взаимодействие клиента с поставщиком — краеугольный камень продаж в целом и формирования…
https://falconspace.ru/blog/bazovye-voprosy-i-ponyatiya-v-sfere-sozdaniya-veb-proektov - Основы веб-разработки. Базовые понятия для владельца сайта
https://falconspace.ru/blog/bazovye-voprosy-i-ponyatiya-v-sfere-sozdaniya-veb-proektov - Основы веб-разработки. Базовые понятия для владельца сайта