I already tried everything and I am still receiving a timeout error. Can someone help me?
private void button1_Click(object sender, EventArgs e)
{
//Execute().Wait();
try
{
MailMessage mail = new MailMessage();
mail.IsBodyHtml = true;
mail.From = new MailAddress("senderEmail");
mail.To.Add(new MailAddress("myemail#gmail.com"));
mail.Subject = "test";
mail.Body = "test";
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.office365.com", 587/* or 25 */);
System.Net.NetworkCredential basicCredential1 = new System.Net.NetworkCredential("username", "password");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = basicCredential1;
client.Timeout = 180000;
client.Send(mail);
MessageBox.Show("sucess");
}
catch (Exception ex)
{
MessageBox.Show("error");
MessageBox.Show(ex.ToString());
}
}
I'm running the application as the admin and I already tried other ports
Related
I have a code on my website to send an email when a user clicks on a button. For some reasons, the code started sending an enormous number of duplicate emails. Actually, it stopped sending when it reached the GoDaddy daily limit, ie. 5000 emails!!!
Is there any way to prevent this situation? Do SMTP timeout helps in this situation?
try
{
SmtpClient client = new SmtpClient("sg2nlvphout-v01.shr.prod.sin2.secureserver.net", 25);
client.EnableSsl = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("email#domain.com", "password");
MailMessage msgobj = new MailMessage();
msgobj.To.Add(email);
msgobj.From = new MailAddress("email#domain.com");
msgobj.Subject = "Subject";
msgobj.Body = body;
AlternateView altView = AlternateView.CreateAlternateViewFromString(msgobj.Body, null, MediaTypeNames.Text.Html);
msgobj.AlternateViews.Add(altView);
client.Send(msgobj);
}
catch (Exception ex)
{
}
try this,
try
{
bool flag = false;
if(!flag)
{
SmtpClient client = new SmtpClient("sg2nlvphout-v01.shr.prod.sin2.secureserver.net", 25);
client.EnableSsl = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("email#domain.com", "password");
MailMessage msgobj = new MailMessage();
msgobj.To.Add(email);
msgobj.From = new MailAddress("email#domain.com");
msgobj.Subject = "Subject";
msgobj.Body = body;
AlternateView altView = AlternateView.CreateAlternateViewFromString(msgobj.Body, null, MediaTypeNames.Text.Html);
msgobj.AlternateViews.Add(altView);
client.Send(msgobj);
flag = true;
}
}
catch (Exception ex)
{
}
using System.Net.Mail;
protected void SendMail()
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.google.com");
SmtpServer.Timeout = 30000;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.From = new MailAddress("myemail#gmail.com");
mail.To.Add("recipient#gmail.com");
mail.Subject = "test";
mail.Body = "test";
mail.Priority = MailPriority.High;
SmtpServer.Port = 587;//25
SmtpServer.Credentials = new System.Net.NetworkCredential("myemail#gmail.com", "pwd");
SmtpServer.EnableSsl = true;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Send(mail);
//MessageBox.Show("mail Send");
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message.ToString());
}
}
I have not found any error in my code as per several sources on internet. Still this is not working out.
Change you gmail Account Access
Sign in with your Google Account and redirect to this link
https://www.google.com/settings/security/lesssecureapps
Press the Enable, and try your code again
https://support.google.com/accounts/answer/6010255
Try this method
In Gmail Use Port-25 and SMTP-smtp.gmail.com
public void mail(string FromEmail, string FromPass, string To, string Tocc, string Tobcc, string subject, string message, string smtpadd, int portnum)
{
try
{
System.Net.Mail.SmtpClient st = new System.Net.Mail.SmtpClient(smtpadd);
System.Net.Mail.MailMessage mst = new System.Net.Mail.MailMessage();
mst.To.Add(To);
if (Tocc != "")
{
mst.CC.Add(Tocc);
}
if (Tobcc != "")
{
mst.Bcc.Add(Tobcc);
}
mst.IsBodyHtml = true;
mst.From = new System.Net.Mail.MailAddress(FromEmail);
mst.Subject = subject;
mst.Body = message;
System.Net.NetworkCredential nc = new System.Net.NetworkCredential(FromEmail, FromPass);
st.UseDefaultCredentials = true;
st.EnableSsl = true;
st.Port = portnum;
st.Credentials = nc;
st.Send(mst);
}
catch (Exception e)
{
}
}
I try to send email but I have An asynchronous module or handler still on hold when the asynchronous operation is complete. I don't know what to do? thanks
My ASPX markup:
<%# Page Language="C#" AutoEventWireup="true"
CodeFile="fotokopiTalebiGorSayfasi.aspx.cs"
Inherits="fotokopiTalebiGorSayfasi" Async="true" %>
My aspx.cs:
public void client_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
}
public bool Email()
{
try
{
SmtpClient client = new SmtpClient("x.x.x.x", 25);
NetworkCredential credential = new NetworkCredential(mailAdres, mailSifre, "DPTDOMAIN");
client.Credentials = credential;
MailMessage message = new MailMessage();
message.From = new MailAddress(mailAdres,"y.m");
message.To.Add(new MailAddress(mailAdres));
message.Subject = "Fotokopi Talep";
message.IsBodyHtml = true;
message.Body = "talep onaylandı";
// client.UseDefaultCredentials = false;
// client.EnableSsl = true;
client.SendAsync(message, 1);
client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
// client.Send(message);
return true;
}
catch (Exception)
{
return false;
//throw new Exception("Mail Gönderirken Bir Hata Oluştu.");
}
}
Here is a template for an email. I helps if you use smtp.port=25;.
try
{
MailMessage msg = new MailMessage ();
MailAddress fromAdd = new MailAddress("fromemail#email.com");
msg.[To].Add("toemail#email.com");
msg.Subject = "Choose Session Members";
msg.From = fromAdd;
msg .IsBodyHtml = true;
msg.Priority = MailPriority.Normal;
msg .BodyEncoding = Encoding.Default;
msg.Body = "<center><table><tr><td><h1>Your Message</h1><br/><br/></td></tr>";
msg.Body = msg.Body + "</table></center>";
SmtpClient smtpClient = new SmtpClient ("smtp.yourserver.com", "25");
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential("yourname#yourserver.com", "password");
smtpClient .DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Send(msg);
smtpClient.Dispose();
}
catch (exception ex){
Label1.Text = ex.ToString();
}
I'm just wondering if i have the correct code to check if a proxy supports SMTP or not. I'm not a spammer or anything it just randomly interested me. I Have this for testing:
//host = proxy IP address
public static void can_mail(string host)
{
MailMessage msg = new MailMessage();
msg.Body = "Email is working!";
msg.From = new MailAddress("me#whatever.com");
msg.IsBodyHtml = false;
msg.Subject = "Mail Test";
msg.To.Add(new MailAddress("myemailaddress#myserver.com"));
try
{
SmtpClient client = new SmtpClient();
client.Host = host;
client.Port = 25;
client.EnableSsl = false;
client.Send(msg);
Console.WriteLine("{0} connected, mail probably works?", host);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.Read();
}
Have I missed something here?
email fail to send when adding attachment, else it's successful
protected void Button1_Click(object sender, EventArgs e)
{
string temp = Session["captcha"].ToString();
if (temp == txtCaptcha.Text)
{
var mail = new System.Net.Mail.MailMessage();
mail.To.Add(#"my mail");
mail.From = new MailAddress("another email", "it's name",
System.Text.Encoding.UTF8);
mail.Subject = "my subject";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = this.txtDescription.Text.Replace("\n", "<br>");
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = System.Net.Mail.MailPriority.High;
var client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("mail", "password");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
if (this.fiUpload1.HasFile)
{
this.fiUpload1.SaveAs(Server.MapPath("MyAttach/" + fiUpload1.FileName));
mail.Attachments.Add(new System.Net.Mail.Attachment(Server.MapPath("MyAttach/" + fiUpload1.FileName)));
}
client.Send(mail);
Page.RegisterStartupScript("UserMsg", "<script>alert('Successfully Send...');</script>");
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
Page.RegisterStartupScript("UserMsg", "<script>alert('Sending Failed...');</script>");
}
}
else
{
Response.Write("Invalid Captcha, try again");
FillCapctha();
}
}
so what am i doing wrong, also should i save the files to my server first or could i just attach it from the client's ?
thanks and have a wonderful day