Click here to Skip to main content
16,017,922 members

Comments by Khan Sarfraz (Top 3 by date)

Khan Sarfraz 9-Nov-11 5:23am View    
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("training@bellatrix.in");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("raghupathirajamca@gmail.com");
message.Body = "hi";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.Send(message);
i used this code error got in last line
Khan Sarfraz 9-Nov-11 5:22am View    
private void Page_Load(object sender, System.EventArgs e)
{
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here

SmtpMail.SmtpServer = "mail.mycompany.com"; //your real server goes here
SmtpMail.Send( mail );
}
Khan Sarfraz 9-Nov-11 5:17am View    
from django.core.mail import send_mail, BadHeaderError

def send_email(request):
subject = request.POST.get('subject', '')
message = request.POST.get('message', '')
from_email = request.POST.get('from_email', '')
if subject and message and from_email:
try:
send_mail(subject, message, from_email, ['admin@example.com'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return HttpResponseRedirect('/contact/thanks/')
else:
# In reality we'd use a form class
# to get proper validation errors.
return HttpResponse('Make sure all fields are entered and valid.')