I am trying to send an email with Asp.Net but the email will not always be sent using the same WIFI credentials.
string email = "noreply#sender.com";
string subject = "Subject";
string MailContent = "This is the content";
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
mail.To.Add(email);
mail.From = new MailAddress("noreplay#reciever.com");
mail.Subject = subject;
mail.IsBodyHtml = true;
mail.Body = MailContent;
SmtpServer.Host = "smtpserver";
SmtpServer.Port = 25;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
SmtpServer.Send(mail);
}
catch (Exception ex)
{
MessageBox.Show("Exception Message: " + ex.Message);
if (ex.InnerException != null)
MessageBox.Show("Exception Inner: " + ex.InnerException);
}
I tried using this code, which was found on a different question but still can't seem to get an error.
Any alternative can work, I have a pdf which would like to be sent on an email or even one drive if possible. Thanks
Related
i developed a simple website that stores in the user name and sends that to my emailid and then downloads a file.File is getting downloaded but not mailing me the username.
try
{
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add("mygmailid");
mailMessage.From =new MailAddress("mydomainbasedemailid");
mailMessage.Subject = "ASP.NET e-mail test";
mailMessage.Body = "Hello world,\n\nThis is an ASP.NET test e-mail!";
SmtpClient smtpClient=new SmtpClient("mail.mydomain.com",587);
smtpClient.Send(mailMessage);
Response.Write("E-mail sent!");
}
catch (Exception ex)
{
Response.Write("Could not send the e-mail - error: " + ex.Message);
}
Try to set the Smtp.Credentials like this:
string HOSTLOGIN = "YourHostLogin";
string HOSTPW = "YourTopSecretPasswort";
var credentials =
new System.Net.NetworkCredential() { UserName = HOSTLOGIN, Password = HOSTPW };
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = credentials;
client.EnableSsl = true;
I am trying to test sending out emails to users from a generic email such as noreply#company.com.
I want to do this in a button click event. How do I achieve this without using credentials?
I have tried several things but I always get errors.
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
mm.To.Add(new System.Net.Mail.MailAddress("Email Address", "Name"));
mm.From = new System.Net.Mail.MailAddress("Email Address");
mm.Sender = new System.Net.Mail.MailAddress("Email Address", "Name");
mm.Subject = "This is Test Email";
mm.Body = "<h3>This is Testing SMTP Mail Send By Me</h3>";
mm.IsBodyHtml = true;
mm.Priority = System.Net.Mail.MailPriority.High; // Set Priority to sending mail
System.Net.Mail.SmtpClient smtCliend = new System.Net.Mail.SmtpClient();
smtCliend.Host = "Your smtp server";
smtCliend.Port = 25; // SMTP port no
smtCliend.Credentials = new NetworkCredential("User Name", "Password");
smtCliend.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
try
{
smtCliend.Send(mm);
}
catch (System.Net.Mail.SmtpException ex)
{
lblMsg.Text = ex.ToString();
}
catch (Exception exe)
{
lblMsg.Text = "\n\n\n" + exe.ToString();
}
Thanks
I am using gmail to send email from C# program, my question is that email found under sent items if logged in into gmail.com via browser?
if I am sent an email from c# program and that email fails(bounce back) then Is failover notification found if I am logged in into gmail.com via browser?
if yes , then is there any additional settings to receive that? I want to show that in gmail.com via browser when I am login.
I don't really understand what you are asking but if you just need the code to send emails through gmail it is pretty simple
void SendMail_Click(object sender, EventArgs e)
{
var email = new Dto.IEmail();
if (EmailBody.Text == string.Empty && EmailSubject.Text == string.Empty)
{
XtraMessageBox.Show("please fill email body and subject");
return;
}
email.Body = EmailBody.Text;
email.Subject = EmailSubject.Text;
email.EmailAddress = "email#gmail.com";
email.ToAddress = "email#gmail.com";
try
{
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();
message.From = new MailAddress(email.EmailAddress);
message.To.Add(new MailAddress(email.ToAddress));
message.Subject = email.Subject;
message.Body = email.Body + "\n From user " + GlobalClass.UserLogin.USERNAME + "\n with body: " + _reportedfile;
smtp.Port = 587;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(email.EmailAddress, "gmailpassword");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(message);
}
catch (Exception ex)
{
XtraMessageBox.Show("err: " + ex.Message);
}
}
Hi I need to send an email using template in c# windows application . I had created a template but i am unable to pass the parameters through the html template. Here is the template which i am using.
For this HTML Template i am calling this in my windows application and sending through gmail smtp. I am able to send the mail but unable to pass the parameters into it. Please Help me out.Here is the code where i am calling in my windows application
try
{
using (StreamReader reader = File.OpenText("H:\\Visitor Management_Project\\Visitor Management_Project\\Visitor Management_Project\\EmailTemplate.htm"))
{
SmtpClient SmtpServer = new SmtpClient("173.194.67.108", 587);
SmtpServer.UseDefaultCredentials = false;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.Credentials = new System.Net.NetworkCredential("ambarishkesavarapu#gmail.com", "*******");
//SmtpServer.Port = 587;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;
message = new MailMessage();
message.Subject = "Visitor Arrived";
//message.SubjectEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
message.Body = "EmailTemplate.htm";
//message.BodyEncoding = System.Text.Encoding.UTF8;
message.From = new MailAddress("ambarishkesavarapu#gmail.com");
message.To.Add(lblCPEmail.Text);
message.Priority = MailPriority.High;
message.Body = reader.ReadToEnd();
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpServer.Send(message);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
How to add Parameters into HTML Template where i am getting all the parameters of that in the same page in Textboxes. Please help me out
I think you already discovered the answer yourself, but I will keep posting the answer instead.
In case you are using Windows Forms and not Windows Presentation Forms (The different only the design part and many new features that does not have on Windows Forms), what I have done is like this (to send email):
public void SendEmail(string _from, string _fromDisplayName, string _to, string _toDisplayName, string _subject, string _body, string _password)
{
try
{
SmtpClient _smtp = new SmtpClient();
MailMessage _message = new MailMessage();
_message.From = new MailAddress(_from, _fromDisplayName); // Your email address and your full name
_message.To.Add(new MailAddress(_to, _toDisplayName)); // The recipient email address and the recipient full name // Cannot be edited
_message.Subject = _subject; // The subject of the email
_message.Body = _body; // The body of the email
_smtp.Port = 587; // Google mail port
_smtp.Host = "smtp.gmail.com"; // Google mail address
_smtp.EnableSsl = true;
_smtp.UseDefaultCredentials = false;
_smtp.Credentials = new NetworkCredential(_from, _password); // Login the gmail using your email address and password
_smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
_smtp.Send(_message);
ShowMessageBox("Your message has been successfully sent.", "Success", 2);
}
catch (Exception ex)
{
ShowMessageBox("Message : " + ex.Message + "\n\nEither your e-mail or password incorrect. (Are you using Gmail account?)", "Error", 1);
}
}
And I am using it like this:
SendEmail(textBox2.Text, textBox5.Text, textBox3.Text, "YOUR_FULL_NAME", textBox4.Text, textBox6.Text, "YOUR_EMAIL_PASSWORD");
Here is the image:
May this answer would help you.
Cheers!
I am trying to send mail to approx. 2000 users. I am sure there is nothing wrong with credentails.
This is my code:
SmtpClient client = new SmtpClient();
client.EnableSsl = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Host = "---";
client.Port = 587;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("---", "---");
MailMessage msg = new MailMessage();
msg.IsBodyHtml = true;
msg.Body = "dfsdf";
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.Subject = "sdfsdf";
msg.From = new MailAddress("---");
msg.Bcc.Clear();
MembershipUserCollection muc = Membership.GetAllUsers();
foreach (MembershipUser mu in muc)
{
msg.Bcc.Add(mu.Email);
}
try
{
client.Send(msg);
}
catch (Exception ex)
{
Label_info.Text = ex.Message;
if (ex.InnerException != null) Label_info.Text += "<br />" + ex.InnerException.Message;
return;
}
This is the exception i get:
Service not available, closing transmission channel. The server response was: 4.7.0 [my smtp name] Error: too many errors