I tried to send an email and set display name of the from Email address. But when i received email in my client for instance gmail. Instead of display name i see email address without domain means From Email "FromEmail#abc.com" then when i received it shows me i received email from "FromEmail".
Here is my code
MailMessage mail = new MailMessage();
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.HeadersEncoding = System.Text.Encoding.UTF8;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Priority = System.Net.Mail.MailPriority.High;
mail.IsBodyHtml = true;
mail.From = new MailAddress("FromEmail#abc.com","Automate");
mail.To.Add(new MailAddress("ToEmail#abc.com"));
mail.Subject = "This is test email";
mail.Body = "This is test mail.";
SmtpClient client = new SmtpClient("smtp.office365.com");
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("senderEmail#abc.com", "*****");
client.Send(mail);
Related
How to send email through SMTP to email address which contain non-ASCII word.
Consider an users with email id : téést#test.com
Code is not throwing any exception and while checking the delivery report it gave an error message:
"Technical details of permanent failure:
local-part of envelope RCPT address contains utf8 but remote server did not offer SMTPUTF8 ".
I am using .net 4.5 and my code sample is :
MailMessage message = new MailMessage();
message.From="test#test.com";
message.Subject = "subject";
message.IsBodyHtml = true;
message.Body = "body";
message.To.Add("téést#test.com");
SmtpClient smtp = new SmtpClient();
smtp.Host = "SMTPServer";
smtp.Port = "SMTPPort";
var userName = "SMTPUserName";
var password = "SMTPPassword";
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(userName, password);
smtp.EnableSsl = true;
smtp.DeliveryFormat = SmtpDeliveryFormat.International;
smtp.Send(message);
Thanks In Advance.
Hi its been almost a day that I've been figuring things out with regards to sending email from godaddy email account to a gmail account. I have had my research online and almost tried everything but no luck .. here's what I made so far.
protected void generateEmail(){
MailMessage mail = new MailMessage ();
mail.From = new System.Net.Mail.MailAddress ("contact#company.com");
// The important part -- configuring the SMTP client
SmtpClient smtp = new SmtpClient ();
smtp.Port = 465; // [1] You can try with 465 also, I always used 587 and got success
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // [2] Added this
smtp.UseDefaultCredentials = false; // [3] Changed this
smtp.Credentials = new NetworkCredential ("contact#company.com", "password123!"); // [4] Added this. Note, first parameter is Email Address of the sender and the next parameter is the password.
smtp.Host = "relay-hosting.secureserver.net";
//recipient address
mail.To.Add (new MailAddress ("test#gmail.com"));
mail.To.Add (new MailAddress ("testagain#gmail.com"));
//Formatted mail body
mail.IsBodyHtml = true;
string st = "This is a Test Message";
mail.Body = st;
smtp.Send (mail);
}
Can anyone help me out ? would appreciate any hands..
protected void generateEmail()
{
//Create the msg object to be sent
MailMessage msg = new MailMessage();
//Add your email address to the recipients
msg.To.Add("whereEmailWillBeSent#gmail.com");
//Configure the address we are sending the mail from
MailAddress address = new MailAddress("mail#company.com");
msg.From = address;
msg.Subject ="Hi this is mail from company";
msg.Body = "Your Message";
SmtpClient client = new SmtpClient();
//for Godaddy
client.Host = "relay-hosting.secureserver.net";
client.Port = 25;
client.EnableSsl = false;
client.UseDefaultCredentials = false;
//Send the msg
client.Send(msg);
//Display some feedback to the user to let them know it was sent
}
}
I have bought a cPanel host and the SMTP server information is:
This is my code:
string smtpAddress = "mandane.hostcream.com";
int portNumber = 465;
bool enableSSL = true;
string emailFrom = "mahabadi#exirsec.ir";
string password = Authenitication.PassWord;
string emailTo = To.Text;
string subject = Subject.Text;
string body = Body.Text;
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(emailFrom);
mail.To.Add(emailTo);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
{
smtp.Credentials = new NetworkCredential(emailFrom, password);
smtp.EnableSsl = enableSSL;
smtp.Send(mail);
}
}
When I run my code and click on the send button after 1 or 2 minutes this appears:
Additional information: Failure sending mail.
What am I doing wrong?
I think you missed something, try this:
SmtpClient smtpClient = new SmtpClient();
NetworkCredential smtpCredentials = new NetworkCredential("email from","password");
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("email from");
MailAddress toAddress = new MailAddress("email to");
smtpClient.Host = "smpt host address";
smtpClient.Port = your_port;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = smtpCredentials;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Timeout = 20000;
message.From = fromAddress;
message.To.Add(toAddress);
message.IsBodyHtml = false;
message.Subject = "example";
message.Body = "example";
smtpClient.Send(message);
It seems that you cannot reach Yahoo address on port 465, please check if this address reachable first because it appears to be a network issue.
I'm trying to send a password reset email, but I'm having trouble figuring out how to specify the sender's address.
Here's what I'm trying to do:
MailMessage mail = new MailMessage();
mail.From.Address = "support#mycompany.com";
mail.To.Add(Email);
mail.Subject = "Forgot Password";
mail.Body = "Click here to reset your password.";
SmtpClient smtp = new SmtpClient();
smtp.SendAsync(mail, null);
I'm sure it's possible, so how can I accomplish this in ASP.Net?
It turns out I was getting ahead of myself.
Removing Address from mail.From.Address allowed me to set the value, but needed the type MailAddress.
Here's the solution:
MailMessage mail = new MailMessage();
mail.From = new MailAddress("support#mycompany.com");
mail.To.Add(Email);
mail.Subject = "Forgot Password";
mail.Body = "Click here to reset your password.";
SmtpClient smtp = new SmtpClient();
smtp.SendAsync(mail, null);
I wrote some codes so as to send e mail but I can only send mail from gmail account to gmail account also, I want to use hotmail accounts how can i do it? thanks
It is
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("xxx#gmail.com");
mail.To.Add("kalaylevent#gmail.com");
mail.Subject = "Test Mail - 1";
mail.IsBodyHtml = true;
string htmlBody;
htmlBody = "Write some HTML code here";
mail.Body = htmlBody;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("kalaylevent#gmail.com", "mypassword");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
I changed a little of code and it tested successfully (from Hotmail to Gmail)
SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
var mail = new MailMessage();
mail.From = new MailAddress("youremail#hotmail.com");
mail.To.Add("to#gmail.com");
mail.Subject = "Test Mail - 1";
mail.IsBodyHtml = true;
string htmlBody;
htmlBody = "Write some HTML code here";
mail.Body = htmlBody;
SmtpServer.Port = 587;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("youremail#hotmail.com", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
I use different smtp client and make sure to set the socket options to StartTls :
using (SmtpClient client = new())
{
try
{
await client.ConnectAsync("smtp.office365.com", 587, SecureSocketOptions.StartTls);
client.AuthenticationMechanisms.Remove("XOAUTH2");
await client.AuthenticateAsync("Your_User_Name", "Your_Password");
await client.SendAsync(mailMessage);
}
catch
{
//log an error message or throw an exception, or both.
throw;
}
finally
{
await client.DisconnectAsync(true);
client.Dispose();
}
}