本文整理汇总了C#中SendGrid.Web.Deliver方法的典型用法代码示例。如果您正苦于以下问题:C# Web.Deliver方法的具体用法?C# Web.Deliver怎么用?C# Web.Deliver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SendGrid.Web
的用法示例。
在下文中一共展示了Web.Deliver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
public ActionResult Send([ModelBinder(typeof(MailModelBinder))]MailModel model, string vendore, string redirectUrl)
{
var username = ConfigurationManager.AppSettings["SendGridUsername"];
var password = ConfigurationManager.AppSettings["SendGridPassword"];
var message = new SendGridMessage();
message.AddTo(ConfigurationManager.AppSettings["SupportToEmail"]);
message.From = new MailAddress(model.To, model.FullName);
message.Subject = model.Subject;
message.Html = model.FullMailBody;
var credentials = new NetworkCredential(username, password);
var transportWeb = new Web(credentials);
transportWeb.Deliver(message);
if (!string.IsNullOrEmpty(vendore))
{
try
{
message = new SendGridMessage();
message.AddTo(vendore.Replace("[", "@"));
message.From = new MailAddress(model.To, model.FullName);
message.Subject = model.Subject;
message.Html = model.FullMailBody;
transportWeb.Deliver(message);
}
catch
{
}
}
return Redirect(redirectUrl);
}
示例2: SendEmail
public void SendEmail(string toEmail)
{
var Password = "5m7TfyhBEG4358L";
var SMTP_SERVER = "smtp.sendgrid.net";
var Username = "[email protected]";
var fromEmail = "[email protected]";
var fromName = "CMU HCI @ HackGT";
var message = "awesome test message";
var credentials = new NetworkCredential(Username, Password);
// Create the email object first, then add the properties.
// Create the email object first, then add the properties.
SendGridMessage myMessage = new SendGridMessage();
myMessage.AddTo(toEmail);
myMessage.From = new MailAddress(fromEmail, fromName);
myMessage.Subject = "SafetyNet - Emergency";
myMessage.Text = message;
// Create an Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
// You can also use the **DeliverAsync** method, which returns an awaitable task.
transportWeb.Deliver(myMessage);
}
示例3: sendEmails
private void sendEmails(Dictionary<string, string> users)
{
if (users.Count < 1)
{
return;
}
var credentials = new NetworkCredential("azure_f8806f6cc6e59f1429[email protected]", "qYzcc6C3Z1A7TB2");
var transportWeb = new Web(credentials);
var myMessage = new SendGridMessage();
myMessage.From = new MailAddress("[email protected]", "ExpInfo team");
myMessage.Text = "Happy Birthday! Thanks for using our servises!";
foreach (var user in users)
{
try
{
myMessage.AddTo(user.Value);
myMessage.Subject = string.Format("Hello, {0}!", user.Key);
// Send the email.
transportWeb.Deliver(myMessage);
}
catch (Exception)
{
}
}
}
示例4: SendMail
private void SendMail()
{
Setup();
var credentials = new NetworkCredential(mySenGridData.UserName, mySenGridData.Pswd);
// Create the email object first, then add the properties.
SendGridMessage myMessage = new SendGridMessage();
myMessage.AddTo(mySenGridData.To);
myMessage.From = new MailAddress(mySenGridData.FromMail, mySenGridData.FromName);
myMessage.Subject = string.Format("Butler Media Process {0} inctance {1}",myRequest.ProcessTypeId,myRequest.ProcessInstanceId);
_MediaServiceContext = new CloudMediaContext(myRequest.MediaAccountName, myRequest.MediaAccountKey);
IAsset x = _MediaServiceContext.Assets.Where(xx => xx.Id == myRequest.AssetId).FirstOrDefault();
AssetInfo ai = new AssetInfo(x);
StringBuilder AssetInfoResume = ai.GetStatsTxt();
AssetInfoResume.AppendLine("");
AssetInfoResume.AppendLine("Media Butler Process LOG " + DateTime.Now.ToString());
foreach (string txt in myRequest.Log)
{
AssetInfoResume.AppendLine(txt);
}
AssetInfoResume.AppendLine("-----------------------------");
myMessage.Html = AssetInfoResume.Replace(" ", " ").Replace(Environment.NewLine, "<br />").ToString();
var transportWeb = new Web(credentials);
transportWeb.Deliver(myMessage);
}
示例5: Send
public void Send(SendGridMessage message)
{
// Create network credentials to access your SendGrid account.
var credentials = new NetworkCredential(_sendGridUsername, _sendGridPassword);
// Create an Web transport for sending email.
var transportWeb = new Web(credentials);
// Disable Unsubsribe
message.DisableUnsubscribe();
var email = ConfigurationManager.AppSettings["TestNotifications"];
var testMessage = new SendGridMessage
{
Subject = message.Subject,
Html = message.Html,
Attachments = message.Attachments,
StreamedAttachments = message.StreamedAttachments
};
testMessage.AddTo(email);
testMessage.From = new MailAddress("[email protected]", "AquaCulture Monitor");
transportWeb.Deliver(testMessage);
}
示例6: SendWithSendGrid
private void SendWithSendGrid(SendGridMessage message) {
var unencodedPassword = Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(_mailSettings.SendGridAccountPassword)));
var credentials = new NetworkCredential(_mailSettings.SendGridAccountName, unencodedPassword);
// Create an Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
transportWeb.Deliver(message);
}
示例7: SendCurrentIncidentInvoiceEmail
public static bool SendCurrentIncidentInvoiceEmail(Incident incident, ApiServices Services)
{
IncidentInfo invoiceIncident = new IncidentInfo(incident);
if (invoiceIncident.PaymentAmount < invoiceIncident.ServiceFee)
{
SendGridMessage invoiceMessage = new SendGridMessage();
invoiceMessage.From = SendGridHelper.GetAppFrom();
invoiceMessage.AddTo(invoiceIncident.IncidentUserInfo.Email);
invoiceMessage.Html = " ";
invoiceMessage.Text = " ";
invoiceMessage.Subject = "StrandD Invoice - Payment for Service Due";
invoiceMessage.EnableTemplateEngine(WebConfigurationManager.AppSettings["RZ_InvoiceTemplateID"]);
invoiceMessage.AddSubstitution("%invoicestub%", new List<string> { invoiceIncident.IncidentGUID.Substring(0, 5).ToUpper() });
invoiceMessage.AddSubstitution("%incidentguid%", new List<string> { invoiceIncident.IncidentGUID });
invoiceMessage.AddSubstitution("%name%", new List<string> { invoiceIncident.IncidentUserInfo.Name });
invoiceMessage.AddSubstitution("%phone%", new List<string> { invoiceIncident.IncidentUserInfo.Phone });
invoiceMessage.AddSubstitution("%email%", new List<string> { invoiceIncident.IncidentUserInfo.Email });
invoiceMessage.AddSubstitution("%jobdescription%", new List<string> { invoiceIncident.JobCode });
invoiceMessage.AddSubstitution("%servicefee%", new List<string> { (invoiceIncident.ServiceFee - invoiceIncident.PaymentAmount).ToString() });
invoiceMessage.AddSubstitution("%datesubmitted%", new List<string> { DateTime.Now.ToShortDateString() });
invoiceMessage.AddSubstitution("%datedue%", new List<string> { (DateTime.Now.AddDays(30)).ToShortTimeString() });
invoiceMessage.AddSubstitution("%servicepaymentlink%", new List<string> { (WebConfigurationManager.AppSettings["RZ_ServiceBaseURL"].ToString() + "/view/customer/incidentpayment/" + invoiceIncident.IncidentGUID) });
// Create an Web transport for sending email.
var transportWeb = new Web(SendGridHelper.GetNetCreds());
// Send the email.
try
{
transportWeb.Deliver(invoiceMessage);
Services.Log.Info("Incident Invoice Email Sent to [" + invoiceIncident.IncidentUserInfo.Email + "]");
return true;
}
catch (InvalidApiRequestException ex)
{
for (int i = 0; i < ex.Errors.Length; i++)
{
Services.Log.Error(ex.Errors[i]);
return false;
}
}
return false;
}
else
{
return false;
}
}
示例8: SendGridEmail
/// <summary>
/// Sends out an email from the application. Returns true if successful.
/// </summary>
public static bool SendGridEmail(string from, List<string> to, List<string> cc, List<string> bcc, string subj, string body, string smtpUser, string smtpUserPwd)
{
try
{
//******************** CONSTRUCT EMAIL ********************************************
// Create the email object first, then add the properties.
var myMessage = new SendGridMessage();
// Add message properties.
myMessage.From = new MailAddress(from);
myMessage.AddTo(to);
if (cc != null)
{
foreach (string cc1 in cc)
myMessage.AddCc(cc1);
}
if (bcc != null)
{
foreach (string bcc1 in bcc)
myMessage.AddBcc(bcc1);
}
myMessage.Subject = subj;
//myMessage.Html = "<p>" + body + "</p>";
myMessage.Text = body;
//*********************************************************************************
//********************* SEND EMAIL ************************************************
var credentials = new NetworkCredential(smtpUser, smtpUserPwd);
// Create an Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
transportWeb.Deliver(myMessage);
return true;
}
catch (Exception ex)
{
if (ex.InnerException != null)
db_Ref.InsertT_OE_SYS_LOG("EMAIL ERR", ex.InnerException.ToString());
else if (ex.Message != null)
db_Ref.InsertT_OE_SYS_LOG("EMAIL ERR", ex.Message.ToString());
else
db_Ref.InsertT_OE_SYS_LOG("EMAIL ERR", "Unknown error");
return false;
}
}
示例9: Send
public void Send()
{
GenerateMessage();
try
{
var credentials = new NetworkCredential("[email protected]", "8cbGXNV0jmXK3YN");
Message.From = new MailAddress("[email protected]", "Inner6");
var transportWeb = new Web(credentials);
transportWeb.Deliver(Message);
}
catch (Exception ex)
{
//Logger.Error("Error sending email", new { Exception = ex });
}
}
示例10: SendMailBatch
/// <summary>
/// Sends the mail batch using the SendGrid API
/// </summary>
/// <param name="mail">The mail.</param>
/// <param name="recipients">The recipients.</param>
/// <param name="onlyTestDontSendMail">if set to <c>true</c> [only test dont send mail].</param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public override bool SendMailBatch(MailInformation mail, IEnumerable<JobWorkItem> recipients, bool onlyTestDontSendMail)
{
var settings = GetSettings();
if (recipients == null || recipients.Any() == false)
throw new ArgumentException("No workitems", "recipients");
if (recipients.Count() > 1000)
throw new ArgumentOutOfRangeException("recipients", "SendGrid supports maximum 1000 recipients per batch send.");
var msg = new SendGridMessage();
msg.From = new MailAddress(mail.From);
msg.Subject = mail.Subject;
msg.Html = mail.BodyHtml;
msg.Text = mail.BodyText;
// Add recipinets to header, to hide other recipients in to field.
List<string> addresses = recipients.Select(r => r.EmailAddress).ToList();
msg.Header.SetTo(addresses);
msg.AddSubstitution("%recipient%", addresses);
// To send message we need to have a to address, set that to from
msg.To = new MailAddress[] { msg.From };
if (mail.EnableTracking)
{
// true indicates that links in plain text portions of the email
// should also be overwritten for link tracking purposes.
msg.EnableClickTracking(true);
msg.EnableOpenTracking();
}
if(mail.CustomProperties.ContainsKey("SendGridCategory"))
{
string category = mail.CustomProperties["SendGridCategory"] as string;
if (string.IsNullOrEmpty(category) == false)
msg.SetCategory(category);
}
var credentials = new NetworkCredential(settings.Username, settings.Password);
// Create an Web transport for sending email.
var transportWeb = new Web(credentials);
transportWeb.Deliver(msg);
return true;
}
示例11: AddSubstitutionValues
/// <summary>
/// This feature allows you to create a message template, and specify different replacement
/// strings for each specific recipient
/// </summary>
public void AddSubstitutionValues()
{
//create a new message object
var message = new SendGridMessage();
//set the message recipients
foreach (var recipient in _to)
{
message.AddTo(recipient);
}
//set the sender
message.From = new MailAddress(_from);
//set the message body
message.Text = "Hi %name%! Pleased to meet you!";
//set the message subject
message.Subject = "Testing Substitution Values";
//This replacement key must exist in the message body
var replacementKey = "%name%";
//There should be one value for each recipient in the To list
var substitutionValues = new List<String> {"Mr Foo", "Mrs Raz"};
message.AddSubstitution(replacementKey, substitutionValues);
//create an instance of the SMTP transport mechanism
var transportInstance = new Web(new NetworkCredential(_username, _password));
//enable bypass list management
message.EnableBypassListManagement();
//send the mail
transportInstance.Deliver(message);
}
示例12: EnableUnsubscribeEmail
/// <summary>
/// Add automatic unsubscribe links to the bottom of emails.
/// http://docs.sendgrid.com/documentation/apps/subscription-tracking/
/// </summary>
public void EnableUnsubscribeEmail()
{
//create a new message object
var message = new SendGridMessage();
//set the message recipients
foreach (var recipient in _to)
{
message.AddTo(recipient);
}
//set the sender
message.From = new MailAddress(_from);
//set the message body
message.Html = "This is the HTML body";
message.Text = "This is the plain text body";
//set the message subject
message.Subject = "Hello World Unsubscribe Test";
//create an instance of the Web transport mechanism
var transportInstance = new Web(new NetworkCredential(_username, _password));
//enable spamcheck
//or optionally, you can specify 'replace' instead of the text and html in order to
//place the link wherever you want.
message.EnableUnsubscribe("Please click the following link to unsubscribe: <% %>",
"Please click <% here %> to unsubscribe");
//send the mail
transportInstance.Deliver(message);
}
示例13: EnableTemplateEmail
/// <summary>
/// This feature wraps an HTML template around your email content.
/// This can be useful for sending out newsletters and/or other HTML formatted messages.
/// http://docs.sendgrid.com/documentation/apps/email-templates/
/// </summary>
public void EnableTemplateEmail()
{
//create a new message object
var message = new SendGridMessage();
//set the message recipients
foreach (var recipient in _to)
{
message.AddTo(recipient);
}
//set the sender
message.From = new MailAddress(_from);
//set the message body
var timestamp = DateTime.Now.ToString("HH:mm:ss tt");
message.Html = "<p style='color:red';>Hello World</p>";
message.Html += "<p>Sent At : " + timestamp + "</p>";
message.Text = "Hello World plain text";
//set the message subject
message.Subject = "Hello World Template Test";
//create an instance of the Web transport mechanism
var transportInstance = new Web(new NetworkCredential(_username, _password));
//enable template
message.EnableTemplate("<p>My Email Template <% body %> is awesome!</p>");
//send the mail
transportInstance.Deliver(message);
}
示例14: EnableSpamCheckEmail
/// <summary>
/// The Spam Checker filter, is useful when your web application allows your end users
/// to create content that is then emailed through your SendGridMessage account.
/// http://docs.sendgrid.com/documentation/apps/spam-checker-filter/
/// </summary>
public void EnableSpamCheckEmail()
{
//create a new message object
var message = new SendGridMessage();
//set the message recipients
foreach (var recipient in _to)
{
message.AddTo(recipient);
}
//set the sender
message.From = new MailAddress(_from);
//set the message body
var timestamp = DateTime.Now.ToString("HH:mm:ss tt");
message.Html = "<p style='color:red';>VIAGRA!!!!!! Viagra!!! CHECKOUT THIS VIAGRA!!!! MALE ENHANCEMENT!!! </p>";
message.Html += "<p>Sent At : " + timestamp + "</p>";
//set the message subject
message.Subject = "WIN A MILLION DOLLARS TODAY! WORK FROM HOME! A NIGERIAN PRINCE WANTS YOU!";
//create an instance of the Web transport mechanism
var transportInstance = new Web(new NetworkCredential(_username, _password));
//enable spamcheck
message.EnableSpamCheck();
//send the mail
transportInstance.Deliver(message);
}
示例15: SendMail
public bool SendMail(string to, string subject, string body)
{
bool result = false;
// Create the email object first, then add the properties.
var myMessage = new SendGridMessage();
// Add the message properties.
myMessage.From = new MailAddress("[email protected]");
// Add multiple addresses to the To field.
List<String> recipients = new List<String>
{
to
};
myMessage.AddTo(recipients);
myMessage.Subject = subject;
//Add the HTML and Text bodies
myMessage.Html = body;
// Create network credentials to access your SendGrid account.
var username = "[email protected]";
var pswd = "EMf0tV9PVhAl4a7";
var credentials = new NetworkCredential(username, pswd);
// Create an Web transport for sending email.
var transportWeb = new Web(credentials);
//System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
//mail.To.Add(to);
//mail.Subject = subject;
//mail.SubjectEncoding = System.Text.Encoding.UTF8;
//mail.Body = body;
//mail.BodyEncoding = System.Text.Encoding.UTF8;
//mail.IsBodyHtml = true;
//mail.Priority = MailPriority.High;
//SmtpClient client = new SmtpClient();
//client.EnableSsl = true; //Gmail works on Server Secured Layer
try
{
// Send the email.
transportWeb.Deliver(myMessage);
result = true;
}
catch (Exception ex)
{
this.serviceLog.LogError("MailService::SendMail", ex);
throw new Exception("something went wrong while sending email ", ex);
} // end try
return result;
}