BEFORE YOU START: To setup your email client with your email, you need to know your POP or IMAP Email Server Settings and ports. To find them, go to the Email Setup Center and write down the information that displays under Email Server Settings.
In web config under app settings you need to configure email Id and password.Your email client may require password authentication for your Outgoing Mail Server.
<configuration>
<appSettings >
<add key="AdminEmail" value="youremailId"/>
<add key="AdminPassword" value="yourpassword"/>
</appSettings>
</configuration>
protected void btnSendmail_Click(object sender, EventArgs e)
{
//Your outgoing server.
using (var client = new SmtpClient("smtpout.asia.secureserver.net", 80))
{
var from = new MailAddress("me@mail.com", "test user");
//In webconfig you have toconfigure your email address and account password under <app settings>
var adminEmail = ConfigurationManager.AppSettings["AdminEmail"];
var adminPassword = ConfigurationManager.AppSettings["AdminPassword"];
var to = new MailAddress(adminEmail, string.Empty);
using (var message = new MailMessage(from, to)){
message.Body = "Thisis a test message!";
message.IsBodyHtml = true;
message.BodyEncoding = Encoding.UTF8;
message.Subject = "Welcome!";
message.SubjectEncoding = Encoding.UTF8;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(adminEmail, adminPassword);
client.Send(message);
}
}
}
Thats all it is working fine.
Post your comments / questions
Recent Article
- ModuleNotFounEerror:No module named celery in Django Project
- How to get domain name information from a Domain using Python
- ModulenotFoundError: no module named 'debug_toolbar' -SOLUTION
- How to create superuser in django project hosted in cPanel without terminal
- CSS & images not loading in django admin | cpanel without terminal
- Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
- How to sell domain name on Godaddy (2023)
- TemplateSyntaxError at / Could not parse the remainder: ' + 1' from 'forloop.counter0 + 1'
Related Article