send email from asp.net via gmail smtp
I have dedicated server. my IP was blocked with only yahoo, since first day. currently i nead 40000 email per day. i decided to create 400 Gmail account and send email from server via gmail smtp server (every gmail account limited to send email to 100 recipients). the ben开发者_开发知识库efit of this solution is all email send to Inbox no SPAM!
what about u? do you have any better solution? do you know any better free email provider with lower limitation?
SmtpClient client = new SmtpClient();
This sounds exactly like a spam setup. I suspect that's why you're blocked from yahoo. I'm sure you are in violation of the Gmail terms of service. I'm sure they'll take less time to ban you than yahoo. You're also missing the point of the 100 recipient limit entirely.
What would I do? Get out of the spam business.
You should register for a professional SMTP service, where they will batch-send your emails. Creating 400 emails account on gmail and access them with code? That sounds VERY un-manageable.
There are commersial websites that work with sending emails that you can integrate with, 40 000 emails per month is a lot of emails, I even think you violate some of googles terms of usage when you adapt this solution.
A normal SMTP service that you can purchase works like this:
- You purchase an email-limit per day/year/month. 40 000 emails will probably be quite costly.
- You integrate with the service with either a Web Service or other API's you DO NOT use SmtpClient ( in some cases you do, but normaly when you send 40 000 emails, that's a NO NO! ).
- You use a template that you've set up in their system, hence, you do not send you own "html" from your code, you use a confirmed / verified template.
Another option is to create a SMTP sender yourself, that batches 40 000 emails during a long time period, but this might get you blacklisted as well.
I'm sure that setting up 400 GMail accounts to send, what sounds a lot like SPAM, is against their T&Cs and it's only a matter of time before they close you down as well.
I would suggest that if you have a legitimate need for sending 40000 emails per day that you sign up with a mail provider who specialises in bulk mailing.
See this for more info: Bulk Mail Sending On The Cheap
MailMessage EmailMsg = new MailMessage();
// EmailMsg.From = new MailAddress("yourmail", "dsd");
// EmailMsg.To.Add(new MailAddress(txtEmail.Text, "from plain text name"));
// EmailMsg.Body = txtMsg.Text;
// EmailMsg.IsBodyHtml = true;
// EmailMsg.Priority = MailPriority.Normal;
// SmtpClient mailClient = new SmtpClient();
// mailClient.Host = ("10.10.11.112");
// //mailClient.Credentials = new System.Net.NetworkCredential("yourmail", "pass");
// mailClient.EnableSsl = false;
// mailClient.Port = 25;
// mailClient.Send(EmailMsg);
i did it this way.Hope it will help you.
public class MailMgmt { private string _From = "asd@gmail.com"; private string _SMTPServer = "smtp.gmail.com"; private int _SMTPPort = "587"; private string _Password = "password"; private bool _EnableSSL = true; private string _To = string.Empty; private string _CC = string.Empty; private string _BCC = string.Empty; private string _Subject = string.Empty; private string _Body = string.Empty; private string _AttachmentFile = string.Empty;
public string From
{
get { return _From; }
set { _From = value; }
}
public string SMTPServer
{
get { return _SMTPServer; }
set { _SMTPServer = value; }
}
public int SMTPPort
{
get { return _SMTPPort; }
set { _SMTPPort = value; }
}
public string Password
{
get { return _Password; }
set { _Password = value; }
}
public bool EnableSSL
{
get { return _EnableSSL; }
set { _EnableSSL = value; }
}
public string To
{
get { return _To; }
set { _To = value.Trim(); }
}
public string CC
{
get { return _CC; }
set { _CC = value.Trim(); }
}
public string BCC
{
get { return _BCC; }
set { _BCC = value.Trim(); }
}
public string Subject
{
get { return _Subject; }
set { _Subject = value.Trim(); }
}
public string Body
{
get { return _Body; }
set { _Body = value.Trim(); }
}
public string AttachmentFile
{
get { return _AttachmentFile; }
set { _AttachmentFile = value.Trim(); }
}
public MailMgmt()
{
}
public void SendMail()
{
bool result = false;
MailMessage obj = new MailMessage();
try
{
string Expression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
string[] StrSpl;
string[] StrSpl1;
obj.From = new MailAddress(_From);
if (_To != "")
{
StrSpl = _To.Split(',');
foreach (string Str in StrSpl)
{
if (Regex.IsMatch(Str, Expression))
{
obj.To.Add(Str);
}
}
}
if (_CC != "")
{
StrSpl = _CC.Split(',');
foreach (string Str in StrSpl)
{
if (Regex.IsMatch(Str, Expression))
{
obj.CC.Add(Str);
}
}
}
if (_BCC != "")
{
StrSpl = _BCC.Split(',');
foreach (string Str in StrSpl)
{
if (Regex.IsMatch(Str, Expression))
{
obj.Bcc.Add(Str);
}
}
}
if (_Subject != "")
{
obj.Subject = _Subject;
}
if (_Body != "")
{
obj.Body = _Body;
}
if (_AttachmentFile != string.Empty)
{
StrSpl1 = _AttachmentFile.Split(',');
foreach (string Str in StrSpl1)
{
Attachment at = new Attachment(Str);
obj.Attachments.Add(at);
}
}
obj.IsBodyHtml = true;
obj.Priority = MailPriority.High;
SmtpClient client = new SmtpClient(_SMTPServer, _SMTPPort);
client.EnableSsl = _EnableSSL;
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(_From, _Password);
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = SMTPUserInfo;
client.Send(obj);
// return result = true;
}
catch (Exception ex)
{
//return result = false;
}
}
}
Use this class and send mail easily
精彩评论