The Way to Programming
The Way to Programming
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Unless you know that the user uses gmail and you know their username and password you can’t send as them you will be sending from your website assuming this is to your support desk to the from and to will be hard coded.
The flat # and the Tenants name can be in the subject and you can cc: the tenant
using System; using System.Linq; using System.Net; using System.Net.Mail; public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button2_Click(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { try { var messagefrom = TextBoxPME.Text; var toAddress = "info@codewithc.com"; string messageBody = TextBoxD.Text; const string fromPassword = "Password"; var subject = "Subject"; var client = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(messagefrom, fromPassword) }; using (var msg = new MailMessage(messagefrom, toAddress) { Subject = subject, Body = messageBody } ) { client.Send(msg); } Response.Write("mail send"); } catch (Exception ex) { Response.Write(ex.Message); } } }
Sign in to your account